-- UNIX Finger Example local function WriteForm(host, user) Write([[ redbean unix finger demo

redbean unix finger demo

Your redbean is able to function as an finger client. Lua server pages can use the unix module to implement protocols that your redbean wasn't originally intended to support. All it takes is few lines of code!



]] % {EscapeHtml(host), EscapeHtml(user)}) end local function main() if IsPublicIp(GetClientAddr()) then ServeError(403) elseif GetMethod() == 'GET' or GetMethod() == 'HEAD' then WriteForm('graph.no', 'new_york') elseif GetMethod() == 'POST' then ip = assert(ResolveIp(GetParam('host'))) fd = assert(unix.socket()) assert(unix.connect(fd, ip, 79)) assert(unix.write(fd, GetParam('user') .. '\r\n')) response = '' while true do data = assert(unix.read(fd)) if data == '' then break end response = response .. data end assert(unix.close(fd)) WriteForm(GetParam('host'), GetParam('user')) Write('
\r\n')
      Write(EscapeHtml(VisualizeControlCodes(response)))
      Write('
\r\n') else ServeError(405) SetHeader('Allow', 'GET, HEAD, POST') end end main()