Annotate

plugins/mod_debug.lua @ 944:2335ece4942d

mod_debug: New debug module (a simplified mod_console, with raw Lua access to a running Prosody's internals)
author Matthew Wild <mwild1@gmail.com>
date Tue, 31 Mar 2009 03:00:40 +0100
child 946:cf4d9e2d33d1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
1 -- Prosody IM v0.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
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
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
13 local console_listener = { default_port = 5582; default_mode = "*l"; };
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
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
105 connlisteners_register('console', console_listener);
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
106
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 -- 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
108 -- 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
109
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 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
111 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
112 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
113 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
114
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 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
116 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
117 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
118 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
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 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
128 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
129 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
130 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
131 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
132
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 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
134 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
135 ____ \ / _
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 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
141
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 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
144 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
145 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
146 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
147
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 local t_insert = table.insert;
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
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
152 local function vdecode(ciphertext, key)
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;
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
156 return (gsub(ciphertext, ".", function (letter)
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 = {
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
164 ["fc3a2603a0795a7d1b192704a3af95fa661e1c5bc63b393ebf75904fa53d3683"] =
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
165 [=[<M|V2n]c30, )Y|X1H" '7 %W3KI1zf6-(vY1(&[cf$[x-(s]=];
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
166 ["40a0da62932391196c18baa1c297e97b14b27bf64689dbe7f8b3b9cfad6cfbee"] =
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
167 [=[]0W!RG6-**2t'%vzz^=8MWh&c<CA30xl;>c38]=];
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
168 ["1ba18bc69e1584170a4ca5d676903141a79c629236e91afa2e14b3e6b0f75a19"] =
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
169 [=[dSU%3nc1*\1y)$8-0Ku[H5K&(-"x3cU^a-*cz{.$!w`9'KQV2Tv)WtN{]=];
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
170 ["a4d8bdafa6ae55d75fc971d193eef41f89499a79dbd24f44999d06025fb7a4f9"] =
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
171 [=[+yNDbYHMP+a`&,d}&]S}7'Nz.3VUM4Ko8Z$42D2EdXNs$S)4!*-dq$|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
172 0WY+a)]+S%X.ndDVG6FVyzp7vVI9x}R14$\YfvvQ("4-$J!/dMT2uZ{+( )
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
173 Z%D0e&UI-L#M.o]=];
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
174 ["7a2ea4b076b8df73131059ac54434337084fd86d05814b37b7beb510d74b2728"] =
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
175 [=[pR)eG%R7-6H}YM++v3'x .aJv)*x(3x wD4ZKy$R+53"+bw(R>Xe|>]=];
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
176 }
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
177
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
178 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
179 if sha256 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
180 local hash = sha256(name..name:reverse(), true);
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 if subst[hash] 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
183 return vdecode(subst[hash], hash);
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 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
185 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
186 end