plugins/mod_debug.lua

Sat, 30 Jan 2010 18:51:07 +0000

author
Matthew Wild <mwild1@gmail.com>
date
Sat, 30 Jan 2010 18:51:07 +0000
changeset 2540
8c52b023f0b9
parent 1523
841d61be198f
permissions
-rw-r--r--

MUC: muc.lib.lua: Fix the sending of the occupant JID instead of the nick in role lists and presence broadcasts after role changes (thanks teo)

1523
841d61be198f Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents: 997
diff changeset
1 -- Prosody IM
944
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
2 -- Copyright (C) 2008-2009 Matthew Wild
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
3 -- Copyright (C) 2008-2009 Waqas Hussain
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
4 --
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
5 -- This project is MIT/X11 licensed. Please see the
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
6 -- COPYING file in the source package for more information.
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
7 --
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
8
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
9 module.host = "*";
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
10
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
11 local connlisteners_register = require "net.connlisteners".register;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
12
997
c81b6141d693 mod_debug: Set default interface to 127.0.0.1
Matthew Wild <mwild1@gmail.com>
parents: 969
diff changeset
13 local console_listener = { default_port = 5583; default_mode = "*l"; default_interface = "127.0.0.1" };
944
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
14
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
15 local sha256, missingglobal = require "util.hashes".sha256;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
16
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
17 local commands = {};
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
18 local debug_env = {};
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
19 local debug_env_mt = { __index = function (t, k) return rawget(_G, k) or missingglobal(k); end, __newindex = function (t, k, v) rawset(_G, k, v); end };
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
20
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
21 local t_insert, t_concat = table.insert, table.concat;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
22 local t_concatall = function (t, sep) local tt = {}; for k, s in pairs(t) do tt[k] = tostring(s); end return t_concat(tt, sep); end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
23
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
24
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
25 setmetatable(debug_env, debug_env_mt);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
26
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
27 console = {};
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
28
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
29 function console:new_session(conn)
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
30 local w = function(s) conn.write(s:gsub("\n", "\r\n")); end;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
31 local session = { conn = conn;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
32 send = function (t) w(tostring(t)); end;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
33 print = function (t) w("| "..tostring(t).."\n"); end;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
34 disconnect = function () conn.close(); end;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
35 };
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
36
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
37 return session;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
38 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
39
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
40 local sessions = {};
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
41
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
42 function console_listener.listener(conn, data)
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
43 local session = sessions[conn];
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
44
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
45 if not session then
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
46 -- Handle new connection
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
47 session = console:new_session(conn);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
48 sessions[conn] = session;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
49 printbanner(session);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
50 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
51 if data then
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
52 -- Handle data
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
53 (function(session, data)
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
54 if data:match("[!.]$") then
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
55 local command = data:lower();
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
56 command = data:match("^%w+") or data:match("%p");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
57 if commands[command] then
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
58 commands[command](session, data);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
59 return;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
60 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
61 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
62
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
63 local chunk, err = loadstring("return "..data);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
64 if not chunk then
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
65 chunk, err = loadstring(data);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
66 if not chunk then
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
67 err = err:gsub("^%[string .-%]:%d+: ", "");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
68 err = err:gsub("^:%d+: ", "");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
69 err = err:gsub("'<eof>'", "the end of the line");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
70 session.print("Sorry, I couldn't understand that... "..err);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
71 return;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
72 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
73 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
74
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
75 debug_env.print = session.print;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
76
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
77 setfenv(chunk, debug_env);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
78
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
79 local ret = { pcall(chunk) };
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
80
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
81 if not ret[1] then
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
82 session.print("Fatal error while running command, it did not complete");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
83 session.print("Error: "..ret[2]);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
84 return;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
85 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
86
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
87 table.remove(ret, 1);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
88
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
89 local retstr = t_concatall(ret, ", ");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
90 if retstr ~= "" then
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
91 session.print("Result: "..retstr);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
92 else
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
93 session.print("No result, or nil");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
94 return;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
95 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
96 end)(session, data);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
97 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
98 session.send(string.char(0));
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
99 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
100
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
101 function console_listener.disconnect(conn, err)
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
102
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
103 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
104
969
9ab6934fb1ff mod_debug: Run on a different port, and use a different listener to mod_console
Matthew Wild <mwild1@gmail.com>
parents: 946
diff changeset
105 connlisteners_register('debug', console_listener);
9ab6934fb1ff mod_debug: Run on a different port, and use a different listener to mod_console
Matthew Wild <mwild1@gmail.com>
parents: 946
diff changeset
106 require "net.connlisteners".start("debug");
944
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
107
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
108 -- Console commands --
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
109 -- These are simple commands, not valid standalone in Lua
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
110
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
111 function commands.bye(session)
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
112 session.print("See you! :)");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
113 session.disconnect();
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
114 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
115
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
116 commands["!"] = function (session, data)
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
117 if data:match("^!!") then
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
118 session.print("!> "..session.env._);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
119 return console_listener.listener(session.conn, session.env._);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
120 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
121 local old, new = data:match("^!(.-[^\\])!(.-)!$");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
122 if old and new then
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
123 local ok, res = pcall(string.gsub, session.env._, old, new);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
124 if not ok then
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
125 session.print(res)
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
126 return;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
127 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
128 session.print("!> "..res);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
129 return console_listener.listener(session.conn, res);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
130 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
131 session.print("Sorry, not sure what you want");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
132 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
133
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
134 function printbanner(session)
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
135 session.print [[
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
136 ____ \ / _
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
137 | _ \ _ __ ___ ___ _-_ __| |_ _
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
138 | |_) | '__/ _ \/ __|/ _ \ / _` | | | |
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
139 | __/| | | (_) \__ \ |_| | (_| | |_| |
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
140 |_| |_| \___/|___/\___/ \__,_|\__, |
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
141 A study in simplicity |___/
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
142
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
143 ]]
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
144 session.print("Welcome to the Prosody debug console. For a list of commands, type: help");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
145 session.print("You may find more help on using this console in our online documentation at ");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
146 session.print("http://prosody.im/doc/debugconsole\n");
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
147 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
148
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
149 local byte, char = string.byte, string.char;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
150 local gmatch, gsub = string.gmatch, string.gsub;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
151
946
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
152 local function vdecode(text, key)
944
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
153 local keyarr = {};
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
154 for l in gmatch(key, ".") do t_insert(keyarr, byte(l) - 32) end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
155 local pos, keylen = 0, #keyarr;
946
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
156 return (gsub(text, ".", function (letter)
944
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
157 if byte(letter) < 32 then return ""; end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
158 pos = (pos%keylen)+1;
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
159 return char(((byte(letter) - 32 - keyarr[pos]) % 94) + 32);
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
160 end));
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
161 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
162
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
163 local subst = {
946
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
164 ["f880c08056ba7dbecb1ccfe5d7728bd6dcd654e94f7a9b21788c43397bae0bc5"] =
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
165 [=[nRYeKR$l'5Ix%u*1Mc-K}*bwv*\ $1KLMBd$KH R38`$[6}VQ@,6Qn]=];
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
166 ["92f718858322157202ec740698c1390e47bc819e52b6a099c54c378a9f7529d6"] =
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
167 [=[V\Z5`WZ5,T$<)7LM'w3Z}M(7V'{pa) &'>0+{v)O(0M*V5K$$LL$|2wT}6
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
168 1as*")e!>]=];
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
169 ["467b65edcc7c7cd70abf2136cc56abd037216a6cd9e17291a2219645be2e2216"] =
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
170 [=[i#'Z,E1-"YaHW(j/0xs]I4x&%(Jx1h&18'(exNWT D3b+K{*8}w(%D {]=];
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
171 ["f73729d7f2fbe686243a25ac088c7e6aead3d535e081329f2817438a5c78bee5"] =
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
172 [=[,3+(Q{3+W\ftQ%wvv/C0z-l%f>ABc(vkp<bb8]=];
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
173 ["6afa189489b096742890d0c5bd17d5bb8af8ac460c7026984b64e8f14a40404e"] =
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
174 [=[9N{)5j34gd*}&]H&dy"I&7(",a F1v6jY+IY7&S+86)1z(Vo]=];
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
175 ["cc5e5293ef8a1acbd9dd2bcda092c5c77ef46d3ec5aea65024fca7ed4b3c94a9"] =
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
176 [=[_]Rc}IF'Kfa&))Ry+6|x!K2|T*Vze)%4Hwz'L3uI|OwIa)|q#uq2+Qu u7
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
177 [V3(z(*TYY|T\1_W'2] Dwr{-{@df#W.H5^x(ydtr{c){UuV@]=];
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
178 ["b3df231fd7ddf73f72f39cb2510b1fe39318f4724728ed58948a180663184d3e"] =
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
179 [=[iH!"9NLS'%geYw3^R*fvWM1)MwxLS!d[zP(p0sQ|8tX{dWO{9w!+W)b"MU
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
180 W)V8&(2Wx"'dTL9*PP%1"JV(I|Jr1^f'-Hc3U\2H3Z='K#,)dPm]=];
944
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
181 }
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
182
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
183 function missingglobal(name)
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
184 if sha256 then
946
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
185 local hash = sha256(name.."|"..name:reverse(), true);
944
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
186
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
187 if subst[hash] then
946
cf4d9e2d33d1 mod_debug: Some updates
Matthew Wild <mwild1@gmail.com>
parents: 944
diff changeset
188 return vdecode(subst[hash], sha256(name:reverse(), true));
944
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
189 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
190 end
2335ece4942d mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
191 end

mercurial