From 505d17a1550422a86cb0dac8bfff234d219d5080 Mon Sep 17 00:00:00 2001 From: plugd Date: Sun, 11 Aug 2024 18:26:53 +0200 Subject: [PATCH] Small refactor, drafted nncp_handler qwk builder. --- qwikboard | 86 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 57 insertions(+), 29 deletions(-) diff --git a/qwikboard b/qwikboard index e9e8bc3..f95f546 100755 --- a/qwikboard +++ b/qwikboard @@ -83,6 +83,10 @@ function fs.rmdir(dirname, force) assert(posix.rmdir(dirname)) end +function fs.rmfile(filename) + posix.unlink(filename) +end + function fs.copy(filename, destfilename) src = assert(io.open(filename,"r")) dest = assert(io.open(destfilename,"w")) @@ -150,6 +154,32 @@ end local qwk = {} +function qwk.build_qwk(user_name, qwk_filename) + local work_dir = fs.mktempdir() + + -- CONTROL.DAT + qwk.write_control(work_dir, user_name) + + -- Copy BBS welcome, news and goodbye files + + fs.copy(qb.path .. "/notices/hello", work_dir .. "/HELLO") + fs.copy(qb.path .. "/notices/news", work_dir .. "/NEWS") + fs.copy(qb.path .. "/notices/goodbye", work_dir .. "/GOODBYE") + + -- Pack messages + + qwk.write_message(work_dir) + + -- Create archive in outgoing + + os.execute(qb.zip .. " -rj " .. + qb.path .. "/" .. qwk_filename .. + " " .. work_dir) + + fs.rmdir(work_dir, true) +end + + function qwk.write_control(target_dir, user_name) local cf = assert(io.open(target_dir .. "/CONTROL.DAT", "w")) @@ -277,10 +307,10 @@ function qwk.process_reply(mf, user_name) end msg.text = string.gsub(msg.text, "\xe3", "\n") - msg.number = get_next_msg_number(qb, conf_num) - set_next_msg_number(qb, conf_num, msg.number+1) + msg.number = get_next_msg_number(conf_num) + set_next_msg_number(conf_num, msg.number+1) - append_new_msg(qb, conf_num, msg) + append_new_msg(conf_num, msg) print("Processed message for conference " .. qb.conferences[conf_num+1] .. ".") @@ -364,31 +394,7 @@ BBSID.QWK, with BBSID being the 8 character ID of the BBS.]] return end - local user_name = arg[1] - local qwk_filename = arg[2] - - local work_dir = fs.mktempdir() - - -- CONTROL.DAT - qwk.write_control(work_dir, qb, user_name) - - -- Copy BBS welcome, news and goodbye files - - fs.copy(qb.path .. "/notices/hello", work_dir .. "/HELLO") - fs.copy(qb.path .. "/notices/news", work_dir .. "/NEWS") - fs.copy(qb.path .. "/notices/goodbye", work_dir .. "/GOODBYE") - - -- Pack messages - - qwk.write_message(work_dir, qb) - - -- Create archive in outgoing - - os.execute(qb.zip .. " -rj " .. - qb.path .. "/" .. qwk_filename .. - " " .. work_dir) - - fs.rmdir(work_dir, true) + qwk.build_qwk(arg[1], arg[2]) end -- repin: read REP file in @@ -437,10 +443,32 @@ be made accessible by user (node) NODENAME by adding the following to their neigh entry in the /etc/nncp.hjson file exec: { - offline: ["/usr/local/bin/qwikboard /var/qb/ nncp_handler"] + offline: ["/usr/local/bin/qwikboard", "/var/bbs/" "nncp_handler"] }]] + return false end + local input_string = io.stdin:read("*all") + + if string.match(string.lower(input_string), "get.*") then + print("Building QWK packet for user '" .. user_name .. "'") + -- Construct QWK packet + + local out_file_name = os.tmpname() + qwk.build_qwk(user_name, out_file_name) + + os.execute(qb.nncp-file .. " " .. out_file_name .. + user_name .. ":" .. qb.bbsid .. ".QWK") + + fs.rmfile(out_file_name) + + else + print("Accepting REP packet from user '" .. user_name .. "'") + -- Accept REP packet + + -- TODO + + end end -- Main -- 2.20.1