Software /
code /
prosody
Annotate
util/prosodyctl/shell.lua @ 10871:e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Tue, 02 Jun 2020 08:01:21 +0100 |
parent | 10869:c91697b81349 |
child | 10873:813e632431e6 |
rev | line source |
---|---|
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 local have_unix, unix = pcall(require, "socket.unix"); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
2 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
3 if not have_unix or type(unix) ~= "table" then |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
4 print("** LuaSocket unix socket support not available or incompatible, ensure your"); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 print("** version is up to date."); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 os.exit(1); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 |
10868
fa06cf7059cd
util.prosodyctl.shell: Use same config option as module for socket path
Kim Alvefur <zash@zash.se>
parents:
10867
diff
changeset
|
9 local config = require "core.configmanager"; |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local server = require "net.server"; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local st = require "util.stanza"; |
10867
561138169983
util.prosodyctl.shell: Join socket path with current data directory
Kim Alvefur <zash@zash.se>
parents:
10859
diff
changeset
|
12 local path = require "util.paths"; |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local have_readline, readline = pcall(require, "readline"); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
16 local adminstream = require "util.adminstream"; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 if have_readline then |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 readline.set_readline_name("prosody"); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local function read_line() |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 if have_readline then |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
24 return readline.readline("prosody> "); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
25 else |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 io.write("prosody> "); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 return io.read("*line"); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
29 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
30 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 local function send_line(client, line) |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
32 client.send(st.stanza("repl-input"):text(line)); |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
33 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
34 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
35 local function repl(client) |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
36 local line = read_line(); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 if not line or line == "quit" or line == "exit" or line == "bye" then |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 if not line then |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
39 print(""); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 os.exit(); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 send_line(client, line); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
46 local function connection(socket_path, listeners) |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 local conn, sock; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
48 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
49 return { |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 connect = function () |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 if sock or conn then |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 return nil, "already connected"; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
54 sock = unix.stream(); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 sock:settimeout(0); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 local ok, err = sock:connect(socket_path); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
57 if not ok then |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
58 return nil, err; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
59 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
60 conn = server.wrapclient(sock, nil, nil, listeners, "*a"); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 return true; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 end; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 disconnect = function () |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 if conn then |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
65 conn:close(); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 conn = nil; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 if sock then |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 sock:close(); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 sock = nil; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
71 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
72 return true; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
73 end; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
74 }; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
75 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
76 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
77 local function printbanner() |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
78 print([[ |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
79 ____ \ / _ |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
80 | _ \ _ __ ___ ___ _-_ __| |_ _ |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
81 | |_) | '__/ _ \/ __|/ _ \ / _` | | | | |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
82 | __/| | | (_) \__ \ |_| | (_| | |_| | |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
83 |_| |_| \___/|___/\___/ \__,_|\__, | |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
84 A study in simplicity |___/ |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
85 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
86 ]]); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 print("Welcome to the Prosody administration console. For a list of commands, type: help"); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 print("You may find more help on using this console in our online documentation at "); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 print("https://prosody.im/doc/console\n"); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 local function start(arg) --luacheck: ignore 212/arg |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 local client = adminstream.client(); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 client.events.add_handler("connected", function () |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 if not arg.quiet then |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 printbanner(); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 repl(client); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 end); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 client.events.add_handler("disconnected", function () |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 print("--- session closed ---"); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 os.exit(); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 end); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 client.events.add_handler("received", function (stanza) |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
108 if stanza.name == "repl-output" or stanza.name == "repl-result" then |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 local result_prefix = stanza.attr.type == "error" and "!" or "|"; |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 print(result_prefix.." "..stanza:get_text()); |
10859
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
111 end |
8de0057b4279
mod_admin_shell, mod_admin_telnet, util.prosodyctl.shell: Separate output from final result
Matthew Wild <mwild1@gmail.com>
parents:
10858
diff
changeset
|
112 if stanza.name == "repl-result" then |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 repl(client); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 end); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
116 |
10869
c91697b81349
util.prosodyctl.shell: Allow passing path to socket on command line
Kim Alvefur <zash@zash.se>
parents:
10868
diff
changeset
|
117 local socket_path = path.resolve_relative_path(prosody.paths.data, arg.socket or config.get("*", "admin_socket") or "prosody.sock"); |
10867
561138169983
util.prosodyctl.shell: Join socket path with current data directory
Kim Alvefur <zash@zash.se>
parents:
10859
diff
changeset
|
118 local conn = connection(socket_path, client.listeners); |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
119 local ok, err = conn:connect(); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
120 if not ok then |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 print("** Unable to connect to server - is it running? Is mod_admin_shell enabled?"); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 print("** Connection error: "..err); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 os.exit(1); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
125 server.loop(); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
126 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
127 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
128 return { |
10871
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10869
diff
changeset
|
129 shell = start; |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
130 }; |