From 1503fd92e68b43f5144c6a3d608b46978d320529 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 Jan 2016 15:18:46 +0100 Subject: rostermanager: Rename variable to avoid name clash [luacheck] --- core/rostermanager.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/rostermanager.lua b/core/rostermanager.lua index f196ccf3..0b72d0a6 100644 --- a/core/rostermanager.lua +++ b/core/rostermanager.lua @@ -300,17 +300,17 @@ local function unsubscribed(username, host, jid) if pending then roster[false].pending[jid] = nil; end - local subscribed; + local is_subscribed; if item then if item.subscription == "from" then item.subscription = "none"; - subscribed = true; + is_subscribed = true; elseif item.subscription == "both" then item.subscription = "to"; - subscribed = true; + is_subscribed = true; end end - local success = (pending or subscribed) and save_roster(username, host, roster); + local success = (pending or is_subscribed) and save_roster(username, host, roster); return success, pending, subscribed; end -- cgit v1.2.3 From 03859deec951c8dad6519db29ff77c00bcebdbce Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 Jan 2016 16:58:39 +0100 Subject: prosodyctl: Show an example ssl config after generating a certificate --- prosodyctl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/prosodyctl b/prosodyctl index e4ef45ad..0c80aca7 100755 --- a/prosodyctl +++ b/prosodyctl @@ -792,6 +792,8 @@ function cert_commands.generate(arg) and openssl.req{new=true, x509=true, nodes=true, key=key_filename, days=365, sha256=true, utf8=true, config=conf_filename, out=cert_filename} then show_message("Certificate written to ".. cert_filename); + print(); + show_message(("Example config:\n\nssl = {\n\tcertificate = %q;\n\tkey = %q;\n}"):format(cert_filename, key_filename)); else show_message("There was a problem, see OpenSSL output"); end -- cgit v1.2.3 From de6d620539e9c011ed344c5847da161d52ec5622 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 Jan 2016 23:54:19 +0100 Subject: net.server_select: Add 'server' method to client connections (present in server_event) --- net/server_select.lua | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/server_select.lua b/net/server_select.lua index d9826c02..eccc7239 100644 --- a/net/server_select.lua +++ b/net/server_select.lua @@ -398,6 +398,9 @@ wrapconnection = function( server, listeners, socket, ip, serverport, clientport out_put "server.lua: closed client handler and removed socket from list" return true end + handler.server = function ( ) + return server + end handler.ip = function( ) return ip end -- cgit v1.2.3 From 6876deedcd6fb44398ae198f1dc2d8c456fc275c Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 10 Jan 2016 00:01:28 +0100 Subject: mod_admin_telnet: Remove compat warning about 'console_banner' as a function --- plugins/mod_admin_telnet.lua | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index b77a1f56..e4dcf080 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -1125,8 +1125,8 @@ end ------------- function printbanner(session) - local option = module:get_option("console_banner"); - if option == nil or option == "full" or option == "graphic" then + local option = module:get_option_string("console_banner", "full"); + if option == "full" or option == "graphic" then session.print [[ ____ \ / _ | _ \ _ __ ___ ___ _-_ __| |_ _ @@ -1137,17 +1137,13 @@ function printbanner(session) ]] end - if option == nil or option == "short" or option == "full" then + if option == "short" or option == "full" then session.print("Welcome to the Prosody administration console. For a list of commands, type: help"); session.print("You may find more help on using this console in our online documentation at "); session.print("http://prosody.im/doc/console\n"); end - if option and option ~= "short" and option ~= "full" and option ~= "graphic" then - if type(option) == "string" then - session.print(option) - elseif type(option) == "function" then - module:log("warn", "Using functions as value for the console_banner option is no longer supported"); - end + if option ~= "short" and option ~= "full" and option ~= "graphic" then + session.print(option); end end -- cgit v1.2.3 From 4ad60283f8f36dcf5ec29c7bd97cd089df46a5d6 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 Jan 2016 23:58:43 +0100 Subject: mod_admin_telnet: c2s:show() etc, list all sessions including unauthenticated or not with no stream opened --- plugins/mod_admin_telnet.lua | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index e4dcf080..c3434d33 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -22,7 +22,7 @@ local console_listener = { default_port = 5582; default_mode = "*a"; interface = local iterators = require "util.iterators"; local keys, values = iterators.keys, iterators.values; -local jid_bare, jid_split = import("util.jid", "bare", "prepped_split"); +local jid_bare, jid_split, jid_join = import("util.jid", "bare", "prepped_split", "join"); local set, array = require "util.set", require "util.array"; local cert_verify_identity = require "util.x509".verify_identity; local envload = require "util.envload".envload; @@ -539,15 +539,26 @@ end def_env.c2s = {}; +local function get_jid(session) + if session.username then + return session.full_jid or jid_join(session.username, session.host, session.resource); + end + return "(unknown)"; +end + local function show_c2s(callback) - for hostname, host in pairs(hosts) do - for username, user in pairs(host.sessions or {}) do - for resource, session in pairs(user.sessions or {}) do - local jid = username.."@"..hostname.."/"..resource; - callback(jid, session); + local c2s = array.collect(values(module:shared"/*/c2s/sessions")); + c2s:sort(function(a, b) + if a.host == b.host then + if a.username == b.username then + return a.resource or "" > b.resource or ""; end + return a.username or "" > b.username or ""; end - end + return a.host or "" > b.host or ""; + end):map(function (session) + callback(get_jid(session), session) + end); end function def_env.c2s:count(match_jid) @@ -563,11 +574,11 @@ end function def_env.c2s:show(match_jid, annotate) local print, count = self.session.print, 0; annotate = annotate or session_flags; - local curr_host; + local curr_host = false; show_c2s(function (jid, session) if curr_host ~= session.host then curr_host = session.host; - print(curr_host); + print(curr_host or "(not connected to any host yet)"); end if (not match_jid) or jid:match(match_jid) then count = count + 1; -- cgit v1.2.3 From 1e0c45235c480931de7c51ae5f8b0e205e977306 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sat, 9 Jan 2016 23:59:31 +0100 Subject: mod_admin_telnet: Show unauthenticated clients identified by local/remote IP and port --- plugins/mod_admin_telnet.lua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index c3434d33..b45db3ef 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -543,7 +543,13 @@ local function get_jid(session) if session.username then return session.full_jid or jid_join(session.username, session.host, session.resource); end - return "(unknown)"; + + local conn = session.conn; + local ip = session.ip or "?"; + local clientport = conn and conn:clientport() or "?"; + local serverip = conn and conn.server and conn:server():ip() or "?"; + local serverport = conn and conn:serverport() or "?" + return jid_join("["..ip.."]:"..clientport, session.host or "["..serverip.."]:"..serverport); end local function show_c2s(callback) -- cgit v1.2.3 From fa8f996af8dca13fbbe567f94a4ab8ff9606da15 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 10 Jan 2016 00:00:22 +0100 Subject: mod_admin_telnet: c2s:count in less lines --- plugins/mod_admin_telnet.lua | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/plugins/mod_admin_telnet.lua b/plugins/mod_admin_telnet.lua index b45db3ef..73698ada 100644 --- a/plugins/mod_admin_telnet.lua +++ b/plugins/mod_admin_telnet.lua @@ -568,13 +568,7 @@ local function show_c2s(callback) end function def_env.c2s:count(match_jid) - local count = 0; - show_c2s(function (jid, session) - if (not match_jid) or jid:match(match_jid) then - count = count + 1; - end - end); - return true, "Total: "..count.." clients"; + return true, "Total: ".. iterators.count(values(module:shared"/*/c2s/sessions")) .." clients"; end function def_env.c2s:show(match_jid, annotate) -- cgit v1.2.3 From 2ff321a3c7f3b705424cf86951e568a810274eed Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 10 Jan 2016 00:17:54 +0100 Subject: Makefile: Add 'test' target that runs tests --- Makefile | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Makefile b/Makefile index 130d8aa7..0138e05c 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,9 @@ clean: rm -f prosody.version $(MAKE) clean -C util-src +test: + cd tests && ./run_tests.sh + util/%.so: $(MAKE) install -C util-src -- cgit v1.2.3 From 93c90c514a73f8a7d4de8d318476ec7641063935 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 10 Jan 2016 03:25:16 +0100 Subject: tests: Correct mistake from latst merge, use the same variable name in all 3 places where it matters --- tests/test.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test.lua b/tests/test.lua index 1192b7b8..87467e53 100644 --- a/tests/test.lua +++ b/tests/test.lua @@ -145,10 +145,10 @@ function dotest(unitname) unit._M = unit; end setfenv(chunk, unit); - local success, err = pcall(chunk); + local success, ret = pcall(chunk); _fakeG.module, _fakeG._M = oldmodule, old_M; if not success then - print("WARNING: ", "Failed to initialise module: "..unitname, err); + print("WARNING: ", "Failed to initialise module: "..unitname, ret); return; end -- cgit v1.2.3 From 0d98ccd02a37153aef1cbfb71ba9c103d43fbda7 Mon Sep 17 00:00:00 2001 From: Kim Alvefur Date: Sun, 10 Jan 2016 03:35:00 +0100 Subject: tests: Add test for util.uuid (checks that the output format is correct) --- tests/test.lua | 1 + tests/test_util_uuid.lua | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 tests/test_util_uuid.lua diff --git a/tests/test.lua b/tests/test.lua index 87467e53..4f6c5335 100644 --- a/tests/test.lua +++ b/tests/test.lua @@ -22,6 +22,7 @@ function run_all_tests() dotest "util.sasl.scram" dotest "util.cache" dotest "util.throttle" + dotest "util.uuid" dosingletest("test_sasl.lua", "latin1toutf8"); dosingletest("test_utf8.lua", "valid"); diff --git a/tests/test_util_uuid.lua b/tests/test_util_uuid.lua new file mode 100644 index 00000000..d3f72bb4 --- /dev/null +++ b/tests/test_util_uuid.lua @@ -0,0 +1,24 @@ +-- This tests the format, not the randomness + +-- https://tools.ietf.org/html/rfc4122#section-4.4 + +local pattern = "^" .. table.concat({ + string.rep("%x", 8), + string.rep("%x", 4), + "4" .. -- version + string.rep("%x", 3), + "[89ab]" .. -- reserved bits of 1 and 0 + string.rep("%x", 3), + string.rep("%x", 12), +}, "%-") .. "$"; + +function generate(generate) + for i = 1, 100 do + assert_is(generate():match(pattern)); + end +end + +function seed(seed) + assert_equal(seed("random string here"), nil, "seed doesn't return anything"); +end + -- cgit v1.2.3