From 3c1dc0bfd0507a593552eef43ce76a2f6d0ad8e8 Mon Sep 17 00:00:00 2001 From: plugd Date: Tue, 13 Aug 2024 18:22:54 +0200 Subject: [PATCH] User<->node mapping now explicitly stored. --- README | 12 +++++------- qwikboard | 38 ++++++++++++++++++++++++++++++++++---- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/README b/README index 3509be3..3b88d88 100644 --- a/README +++ b/README @@ -92,11 +92,14 @@ we could use: Any of these neighbours can then retrieve QWK files using: - echo get | nncp-exec bbsnode qwikboard + echo get USER | nncp-exec bbsnode qwikboard This will result in the QWK file being assembled sent to the requesting node using nncp-file, meaning the requesting node will also -need an incoming directory specified. +need an incoming directory specified. The "USER" argument specifies +the handle which will be associated with the requesting node +when replies are sent. (It is an error to request a packet for +a username which has already been associated with another node.) Similarly, REP files can be submitted using: @@ -105,11 +108,6 @@ Similarly, REP files can be submitted using: This will result in the messages contained in replyfile.rep being incorporated into the message database. -The nncp_handler command assumes that the name of the sending NNCP -node is the name of the user. Thus, when registering users to the -BBS, ensure that you configure their node names appropriately in -nncp.hjson. - License ------- diff --git a/qwikboard b/qwikboard index 63dd32d..f48f32c 100755 --- a/qwikboard +++ b/qwikboard @@ -392,6 +392,8 @@ function cmd.init () fs.touch(qb.path .. "/notices/hello") fs.touch(qb.path .. "/notices/news") fs.touch(qb.path .. "/notices/goodbye") + + fs.touch(qb.path .. "/nncp_users.lua") end -- qwkout: generate QWK file @@ -428,12 +430,25 @@ about this.]] qwk.import_rep(arg[1], arg[2]) end +local function restore_nncp_usernames() + nncp_usernames = {} + dofile(qb.path .. "/nncp_users.lua") +end + +local function store_nncp_usernames() + local fh = assert(io.open(qb.path .. "/nncp_users.lua", "w")) + for k,v in pairs(nncp_usernames) do + fh:write("nncp_usernames[" .. string.format("%q",k) .. "] = " .. + string.format("%q", v) .. "\n") + end +end + function cmd.nncp_handler() load_config() - local user_name = os.getenv("NNCP_SENDER") + local node_id = os.getenv("NNCP_SENDER") - if not user_name then + if not node_id then print [[The nncp_handler command is intended to be called by nncp on receipt of an exec packet. For instance, the offline BBS could be made accessible by user (node) NODENAME by adding the following @@ -445,9 +460,17 @@ exec: { return false end + restore_nncp_usernames() + local input_string = io.stdin:read("*all") - if string.match(string.lower(input_string), "get.*") then + if string.match(input_string, "^get%s%w+%s$") then + + local user_name = string.match(input_string, "^get%s(%w+)%s$") + + nncp_usernames[node_id] = user_name + store_nncp_usernames() + print("Building QWK packet for user '" .. user_name .. "'") -- Construct QWK packet @@ -458,13 +481,20 @@ exec: { qwk.build_qwk(user_name, out_file_name) print(qb.nncp_file .. " " .. out_file_name .. " " .. - user_name .. ":" .. qb.bbsid .. ".QWK") + node_id .. ":" .. qb.bbsid .. ".QWK") os.execute(qb.nncp_file .. " " .. out_file_name .. " " .. user_name .. ":" .. qb.bbsid .. ".QWK") fs.rmfile(out_file_name) else + local user_name = nncp_usernames[node_id] + + if not user_name then + print("No user name for node " .. node_id .. " found. Aborting.") + return false + end + print("Accepting REP packet from user '" .. user_name .. "'") -- Accept REP packet -- 2.20.1