end
end
+local function space_pad(s, n)
+ return string.sub(s,1,n) .. string.rep(" ", math.max(0,n-string.len(s)))
+end
local fs = {}
return posix.mkdtemp("/tmp/obbs-XXXXXX")
end
+--- QWK formatting ---
+
+local qwk = {}
+
+function qwk.write_control(cf, obbs, user_name)
+ cf:write(obbs.name .. "\r\n")
+ cf:write("\r\n") -- BBS location
+ cf:write("\r\n") -- BBS phone number
+ cf:write(obbs.sysop .. "\r\n")
+ cf:write("," .. obbs.bbsid .. "\r\n")
+ cf:write(os.date("%d-%m-%Y,%X") .. "\r\n") -- packet creation time
+ cf:write(user_name .. "\r\n")
+ cf:write("\r\n")
+ cf:write(0 .. "\r\n")
+ cf:write(0 .. "\r\n") -- TODO: Number of messages in packet
+ cf:write(#obbs.conferences-1 .. "\r\n") -- Index of final conference
+ for i,v in ipairs(obbs.conferences) do
+ cf:write(i-1 .. "\r\n")
+ cf:write(v .. "\r\n")
+ end
+
+ cf:write("HELLO\r\n")
+ cf:write("NEWS\r\n")
+ cf:write("GOODBYE\r\n")
+end
+
+function qwk.write_message (mf, obbs)
+ mf:write(space_pad("Produced by Qmail...Copyright (c) 1987 by Sparkware." ..
+ " All Rights Reserved", 128))
+
+ for cnum,cname in ipairs(obbs.conferences) do
+ for mnum,msg_fname in ipairs(posix.dir(obbs.path .. "/conferences/" .. cname)) do
+ msg = io.open(obbs.path .. "/conferences/" .. cname .. "/" .. msg_fname, "r"):read("*all")
+
+ qwk.write_message_header_block(mf, obbs, cnum, mnum, msg)
+ qwk.write_message_blocks(mf, obbs, msg)
+ end
+ end
+end
+
+function qwk.write_message_header_block(mf, obbs, conf_num, msg)
+end
+
+function qwk.write_message_blocks(mf, obbs, msg)
+end
--- Commands ---
print [[
-- OBBS Configuration File
+obbs.path = "." -- Path to OBBS root
+
obbs.name = "My OBBS Name"
obbs.bbsid = "MYOBBSID" -- max 8 char
obbs.sysop = "Sysop Name"
function cmd.init ()
load_config()
- if fs.exists("conferences") or
- fs.exists("incoming") or
- fs.exists("outgoing") then
+ if fs.exists(obbs.path .. "/conferences") or
+ fs.exists(obbs.path .. "/incoming") or
+ fs.exists(obbs.path .. "/outgoing") then
print("One or more OBBS directories already exist. Aborting.")
return
end
- fs.mkdir("conferences")
+ fs.mkdir(obbs.path .. "conferences")
for i,v in ipairs(obbs.conferences) do
- fs.mkdir("conferences/" .. v)
+ fs.mkdir(obbs.path .. "conferences/" .. v)
end
- fs.mkdir("incoming")
- fs.mkdir("outgoing")
+ fs.mkdir(obbs.path .. "incoming")
+ fs.mkdir(obbs.path .. "outgoing")
end
-- Pack
-- CONTROL.DAT
local cf = assert(io.open(dir .. "/CONTROL.DAT", "w"))
- cf:write(obbs.name .. "\r\n")
- cf:write("\r\n") -- BBS location
- cf:write("\r\n") -- BBS phone number
- cf:write(obbs.sysop .. "\r\n")
- cf:write("," .. obbs.bbsid .. "\r\n")
- cf:write(os.date("%d-%m-%Y,%X") .. "\r\n") -- packet creation time
- cf:write(user_name .. "\r\n")
- cf:write("\r\n")
- cf:write(0 .. "\r\n")
- cf:write(0 .. "\r\n") -- TODO: Number of messages in packet
- cf:write(#obbs.conferences-1 .. "\r\n") -- Index of final conference
- for i,v in ipairs(obbs.conferences) do
- cf:write(i-1 .. "\r\n")
- cf:write(v .. "\r\n")
- end
-
- cf:write("HELLO\r\n")
- cf:write("NEWS\r\n")
- cf:write("GOODBYE\r\n")
+ qwk.write_control(cf, obbs, user_name)
cf:close()
-- Copy BBS welcome, news and goodbye files
-- Pack messages
+ local mf = assert(io.open(dir .. "/MESSAGES.DAT", "w"))
+ qwk.write_message(mf, obbs)
+ mf:close()
+
-- Create archive in outgoing
- os.execute("zip -rj outgoing/" .. obbs.bbsid .. ".qwk " .. dir)
+ os.execute("zip -rj " .. obbs.path ..
+ "/outgoing/" .. obbs.bbsid ..
+ ".qwk " .. dir)
fs.rmdir(dir)
end