util/prosodyctl/shell.lua
author Matthew Wild <mwild1@gmail.com>
Mon, 01 Jun 2020 15:44:44 +0100
changeset 10862 efa49d484560
child 10863 8de0057b4279
permissions -rw-r--r--
prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10862
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
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 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
    10
local st = require "util.stanza";
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    11
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    12
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
    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 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
    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
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
    17
	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
    18
end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    19
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    20
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
    21
	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
    22
		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
    23
	else
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    24
		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
    25
		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
    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
end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    28
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    29
local function 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
    30
	client.send(st.stanza("repl-line"):text(line));
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    31
end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    32
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 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
    34
	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
    35
	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
    36
		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
    37
			print("");
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    38
		end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    39
		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
    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
	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
    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
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    44
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
    45
	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
    46
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    47
	return {
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    48
		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
    49
			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
    50
				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
    51
			end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    52
			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
    53
			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
    54
			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
    55
			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
    56
				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
    57
			end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    58
			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
    59
			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
    60
		end;
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    61
		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
    62
			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
    63
				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
    64
				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
    65
			end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    66
			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
    67
				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
    68
				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
    69
			end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    70
			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
    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
	};
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
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
    76
	print([[
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    77
                     ____                \   /     _
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    78
                    |  _ \ _ __ ___  ___  _-_   __| |_   _
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
                    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
    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
]]);
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    85
	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
    86
	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
    87
	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
    88
end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    89
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    90
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
    91
	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
    92
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    93
	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
    94
		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
    95
			printbanner();
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    96
		end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
    97
		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
    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
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   100
	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
   101
		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
   102
		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
   103
	end);
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   104
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   105
	client.events.add_handler("received", function (stanza)
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   106
		if stanza.name == "repl-result" then
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   107
			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
   108
			print(result_prefix.." "..stanza:get_text());
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   109
			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
   110
		end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   111
	end);
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   112
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   113
	local conn = connection("data/prosody.sock", client.listeners);
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   114
	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
   115
	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
   116
		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
   117
		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
   118
		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
   119
	end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   120
	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
   121
end
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   122
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   123
return {
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   124
	start = start;
efa49d484560 prosodyctl, util.prosodyctl.shell: `prosodyctl shell` - a client to access the prosodyctl admin shell
Matthew Wild <mwild1@gmail.com>
parents:
diff changeset
   125
};