Software /
code /
prosody
Annotate
util/prosodyctl/shell.lua @ 11459:86904555bffc
teal: Use new integer support in Teal 0.13.0
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 18 Mar 2021 23:16:41 +0100 |
parent | 11423:0a10bb3b129b |
child | 11520:0a464a6e88c4 |
rev | line source |
---|---|
10868
fa06cf7059cd
util.prosodyctl.shell: Use same config option as module for socket path
Kim Alvefur <zash@zash.se>
parents:
10867
diff
changeset
|
1 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
|
2 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
|
3 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
|
4 local path = require "util.paths"; |
10874
98c535531450
util.prosodyctl.shell: Really fix --socket option
Kim Alvefur <zash@zash.se>
parents:
10873
diff
changeset
|
5 local parse_args = require "util.argparse".parse; |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 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
|
8 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 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
|
10 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 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
|
12 readline.set_readline_name("prosody"); |
10877
2b015ef8cd06
util.prosodyctl.shell: Save readline history
Kim Alvefur <zash@zash.se>
parents:
10875
diff
changeset
|
13 readline.set_options({ |
2b015ef8cd06
util.prosodyctl.shell: Save readline history
Kim Alvefur <zash@zash.se>
parents:
10875
diff
changeset
|
14 histfile = path.join(prosody.paths.data, ".shell_history"); |
2b015ef8cd06
util.prosodyctl.shell: Save readline history
Kim Alvefur <zash@zash.se>
parents:
10875
diff
changeset
|
15 ignoredups = true; |
2b015ef8cd06
util.prosodyctl.shell: Save readline history
Kim Alvefur <zash@zash.se>
parents:
10875
diff
changeset
|
16 }); |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 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
|
20 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
|
21 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
|
22 else |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
23 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
|
24 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
|
25 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
26 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
27 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 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
|
29 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
|
30 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
31 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
32 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
|
33 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
|
34 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
|
35 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
|
36 print(""); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
10877
2b015ef8cd06
util.prosodyctl.shell: Save readline history
Kim Alvefur <zash@zash.se>
parents:
10875
diff
changeset
|
38 if have_readline then |
2b015ef8cd06
util.prosodyctl.shell: Save readline history
Kim Alvefur <zash@zash.se>
parents:
10875
diff
changeset
|
39 readline.save_history(); |
2b015ef8cd06
util.prosodyctl.shell: Save readline history
Kim Alvefur <zash@zash.se>
parents:
10875
diff
changeset
|
40 end |
10858
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 printbanner() |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
47 print([[ |
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 | _ \ _ __ ___ ___ _-_ __| |_ _ |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
50 | |_) | '__/ _ \/ __|/ _ \ / _` | | | | |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
51 | __/| | | (_) \__ \ |_| | (_| | |_| | |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
52 |_| |_| \___/|___/\___/ \__,_|\__, | |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
53 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
|
54 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
55 ]]); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
56 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
|
57 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
|
58 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
|
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 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
61 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
|
62 local client = adminstream.client(); |
10938
a5b8ae066688
util.prosodyctl.shell: Collect extra return values
Kim Alvefur <zash@zash.se>
parents:
10937
diff
changeset
|
63 local opts, err, where = parse_args(arg); |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 |
10937
d86f59c31458
util.prosodyctl.shell: Handle argument parsing errors
Kim Alvefur <zash@zash.se>
parents:
10877
diff
changeset
|
65 if not opts then |
d86f59c31458
util.prosodyctl.shell: Handle argument parsing errors
Kim Alvefur <zash@zash.se>
parents:
10877
diff
changeset
|
66 if err == "param-not-found" then |
d86f59c31458
util.prosodyctl.shell: Handle argument parsing errors
Kim Alvefur <zash@zash.se>
parents:
10877
diff
changeset
|
67 print("Unknown command-line option: "..tostring(where)); |
d86f59c31458
util.prosodyctl.shell: Handle argument parsing errors
Kim Alvefur <zash@zash.se>
parents:
10877
diff
changeset
|
68 elseif err == "missing-value" then |
d86f59c31458
util.prosodyctl.shell: Handle argument parsing errors
Kim Alvefur <zash@zash.se>
parents:
10877
diff
changeset
|
69 print("Expected a value to follow command-line option: "..where); |
d86f59c31458
util.prosodyctl.shell: Handle argument parsing errors
Kim Alvefur <zash@zash.se>
parents:
10877
diff
changeset
|
70 end |
d86f59c31458
util.prosodyctl.shell: Handle argument parsing errors
Kim Alvefur <zash@zash.se>
parents:
10877
diff
changeset
|
71 os.exit(1); |
d86f59c31458
util.prosodyctl.shell: Handle argument parsing errors
Kim Alvefur <zash@zash.se>
parents:
10877
diff
changeset
|
72 end |
d86f59c31458
util.prosodyctl.shell: Handle argument parsing errors
Kim Alvefur <zash@zash.se>
parents:
10877
diff
changeset
|
73 |
11423
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
74 if arg[1] then |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
75 if arg[2] then |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
76 -- TODO send each arg[] and wait for reply? |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
77 print("Only one command is supported as argument"); |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
78 os.exit(1); |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
79 end |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
80 |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
81 client.events.add_handler("connected", function() |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
82 client.send(st.stanza("repl-input"):text(arg[1])); |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
83 return true; |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
84 end, 1); |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
85 |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
86 local errors = 0; -- TODO This is weird, but works for now. |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
87 client.events.add_handler("received", function(stanza) |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
88 if stanza.name == "repl-output" or stanza.name == "repl-result" then |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
89 if stanza.attr.type == "error" then |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
90 errors = errors + 1; |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
91 io.stderr:write(stanza:get_text(), "\n"); |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
92 else |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
93 print(stanza:get_text()); |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
94 end |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
95 end |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
96 if stanza.name == "repl-result" then |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
97 os.exit(errors); |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
98 end |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
99 return true; |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
100 end, 1); |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
101 end |
0a10bb3b129b
util.prosodyctl.shell: Allow passing a single command as argument
Kim Alvefur <zash@zash.se>
parents:
11422
diff
changeset
|
102 |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 client.events.add_handler("connected", function () |
11422
fa5a23d7aabc
util.prosodyctl.shell: Fix check for --quiet
Kim Alvefur <zash@zash.se>
parents:
10938
diff
changeset
|
104 if not opts.quiet 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
|
105 printbanner(); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 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
|
108 end); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 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
|
111 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
|
112 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
|
113 end); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
114 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
115 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
|
116 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 end); |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
124 |
10874
98c535531450
util.prosodyctl.shell: Really fix --socket option
Kim Alvefur <zash@zash.se>
parents:
10873
diff
changeset
|
125 local socket_path = path.resolve_relative_path(prosody.paths.data, opts.socket or config.get("*", "admin_socket") or "prosody.sock"); |
10875
09674bbb833f
util.prosodyctl.shell, util.adminstream: Move connection logic into adminstream for easier reuse
Matthew Wild <mwild1@gmail.com>
parents:
10874
diff
changeset
|
126 local conn = adminstream.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
|
127 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
|
128 if not ok then |
10875
09674bbb833f
util.prosodyctl.shell, util.adminstream: Move connection logic into adminstream for easier reuse
Matthew Wild <mwild1@gmail.com>
parents:
10874
diff
changeset
|
129 if err == "no unix socket support" then |
09674bbb833f
util.prosodyctl.shell, util.adminstream: Move connection logic into adminstream for easier reuse
Matthew Wild <mwild1@gmail.com>
parents:
10874
diff
changeset
|
130 print("** LuaSocket unix socket support not available or incompatible, ensure your"); |
09674bbb833f
util.prosodyctl.shell, util.adminstream: Move connection logic into adminstream for easier reuse
Matthew Wild <mwild1@gmail.com>
parents:
10874
diff
changeset
|
131 print("** version is up to date."); |
09674bbb833f
util.prosodyctl.shell, util.adminstream: Move connection logic into adminstream for easier reuse
Matthew Wild <mwild1@gmail.com>
parents:
10874
diff
changeset
|
132 else |
09674bbb833f
util.prosodyctl.shell, util.adminstream: Move connection logic into adminstream for easier reuse
Matthew Wild <mwild1@gmail.com>
parents:
10874
diff
changeset
|
133 print("** Unable to connect to server - is it running? Is mod_admin_shell enabled?"); |
09674bbb833f
util.prosodyctl.shell, util.adminstream: Move connection logic into adminstream for easier reuse
Matthew Wild <mwild1@gmail.com>
parents:
10874
diff
changeset
|
134 print("** Connection error: "..err); |
09674bbb833f
util.prosodyctl.shell, util.adminstream: Move connection logic into adminstream for easier reuse
Matthew Wild <mwild1@gmail.com>
parents:
10874
diff
changeset
|
135 end |
10858
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
136 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
|
137 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
138 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
|
139 end |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
140 |
efa49d484560
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
141 return { |
10871
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10869
diff
changeset
|
142 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
|
143 }; |