Mercurial > prosody-hg
comparison util/prosodyctl/shell.lua @ 13590:d66f30855822
util.prosodyctl.shell: Support for requesting special inputs, e.g. passwords
This lets the server signal to the client that a special input is requested.
Currently we support the "password" type only.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Tue, 07 Jan 2025 18:10:59 +0000 |
| parents | 7b070909bd15 |
| children | ca9426f98b8e |
comparison
equal
deleted
inserted
replaced
| 13589:b1b931d5fee8 | 13590:d66f30855822 |
|---|---|
| 1 local config = require "prosody.core.configmanager"; | 1 local config = require "prosody.core.configmanager"; |
| 2 local human_io = require "prosody.util.human.io"; | |
| 2 local server = require "prosody.net.server"; | 3 local server = require "prosody.net.server"; |
| 3 local st = require "prosody.util.stanza"; | 4 local st = require "prosody.util.stanza"; |
| 4 local path = require "prosody.util.paths"; | 5 local path = require "prosody.util.paths"; |
| 5 local parse_args = require "prosody.util.argparse".parse; | 6 local parse_args = require "prosody.util.argparse".parse; |
| 6 local tc = require "prosody.util.termcolours"; | 7 local tc = require "prosody.util.termcolours"; |
| 129 print("--- session closed ---"); | 130 print("--- session closed ---"); |
| 130 os.exit(0, true); | 131 os.exit(0, true); |
| 131 end); | 132 end); |
| 132 | 133 |
| 133 client.events.add_handler("received", function (stanza) | 134 client.events.add_handler("received", function (stanza) |
| 135 if stanza.name ~= "repl-request-input" then | |
| 136 return; | |
| 137 end | |
| 138 if stanza.attr.type == "password" then | |
| 139 local password = human_io.read_password(); | |
| 140 client.send(st.stanza("repl-requested-input", { type = stanza.attr.type, id = stanza.attr.id }):text(password)); | |
| 141 else | |
| 142 io.stderr:write("Internal error - unexpected input request type "..tostring(stanza.attr.type).."\n"); | |
| 143 os.exit(1); | |
| 144 end | |
| 145 return true; | |
| 146 end, 2); | |
| 147 | |
| 148 | |
| 149 client.events.add_handler("received", function (stanza) | |
| 134 if stanza.name == "repl-output" or stanza.name == "repl-result" then | 150 if stanza.name == "repl-output" or stanza.name == "repl-result" then |
| 135 local result_prefix = stanza.attr.type == "error" and "!" or "|"; | 151 local result_prefix = stanza.attr.type == "error" and "!" or "|"; |
| 136 local out = result_prefix.." "..stanza:get_text(); | 152 local out = result_prefix.." "..stanza:get_text(); |
| 137 if ttyout and stanza.attr.type == "error" then | 153 if ttyout and stanza.attr.type == "error" then |
| 138 out = tc.getstring(tc.getstyle("red"), out); | 154 out = tc.getstring(tc.getstyle("red"), out); |
| 162 server.loop(); | 178 server.loop(); |
| 163 end | 179 end |
| 164 | 180 |
| 165 return { | 181 return { |
| 166 shell = start; | 182 shell = start; |
| 183 check_host = check_host; | |
| 167 }; | 184 }; |
