mirror of
https://github.com/ShadowKatStudios/OC-Minitel.git
synced 2024-11-23 02:28:05 +11:00
added the frequest stuff, will document protocol later but it's basically gopher minus hypertext
This commit is contained in:
parent
8adb476dde
commit
46b9a8c655
68
FRequest/OpenOS/etc/rc.d/fserv.lua
Normal file
68
FRequest/OpenOS/etc/rc.d/fserv.lua
Normal file
@ -0,0 +1,68 @@
|
||||
local net = require "net"
|
||||
local fs = require "filesystem"
|
||||
local event = require "event"
|
||||
|
||||
local prefix = "/srv"
|
||||
local process = nil
|
||||
local listener = nil
|
||||
local dbug = false
|
||||
|
||||
local function dprint(...)
|
||||
if dbug then
|
||||
print(...)
|
||||
end
|
||||
end
|
||||
|
||||
function start()
|
||||
process = net.flisten(70,function(s)
|
||||
local buffer = ""
|
||||
local function lf()
|
||||
buffer=s:read(1024)
|
||||
local nl = buffer:find("\n")
|
||||
if nl then
|
||||
local path=prefix .. "/" .. buffer:sub(1,nl-1)
|
||||
dprint(path)
|
||||
if fs.exists(path) then
|
||||
if fs.isDirectory(path) then
|
||||
if fs.exists(path.."/index") then
|
||||
s:write(f:read("*a"))
|
||||
end
|
||||
local dbuffer = ""
|
||||
for f in fs.list(path) do
|
||||
dbuffer = dbuffer..f.."\n"
|
||||
dprint(f)
|
||||
end
|
||||
s:write(dbuffer)
|
||||
s:close()
|
||||
else
|
||||
local f = io.open(path,"rb")
|
||||
s:write(f:read("*a"))
|
||||
f:close()
|
||||
s:close()
|
||||
end
|
||||
else
|
||||
dprint("404")
|
||||
s:write("file not found")
|
||||
s:close()
|
||||
end
|
||||
end
|
||||
end
|
||||
listener = lf
|
||||
event.listen("net_msg",lf)
|
||||
end)
|
||||
end
|
||||
|
||||
function stop()
|
||||
event.ignore("net_msg",listener)
|
||||
event.ignore("net_msg",process)
|
||||
end
|
||||
|
||||
function debug()
|
||||
dbug = not dbug
|
||||
end
|
||||
function set_path(newpath)
|
||||
if fs.exists(newpath) then
|
||||
prefix=newpath
|
||||
print("prefix = "..newpath)
|
||||
end
|
||||
end
|
20
FRequest/OpenOS/usr/bin/fget.lua
Normal file
20
FRequest/OpenOS/usr/bin/fget.lua
Normal file
@ -0,0 +1,20 @@
|
||||
local net = require "net"
|
||||
local event = require "event"
|
||||
|
||||
local tArgs = {...}
|
||||
local host, path = tArgs[1], tArgs[2]
|
||||
local port = 70
|
||||
|
||||
local sep = host:find(":")
|
||||
if sep then
|
||||
port=tonumber(host:sub(sep+1))
|
||||
host=host:sub(1,sep-1)
|
||||
end
|
||||
|
||||
local s = net.open(host,port)
|
||||
s:write(path.."\n")
|
||||
repeat
|
||||
l = s:read(1024)
|
||||
io.write(l)
|
||||
os.sleep(0.5)
|
||||
until s.state == "closed" and l == ""
|
Loading…
Reference in New Issue
Block a user