Software /
code /
prosody
Comparison
plugins/mod_admin_shell.lua @ 12977:74b9e05af71e
plugins: Prefix module imports with prosody namespace
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Fri, 24 Mar 2023 13:15:28 +0100 |
parent | 12927:918dfbb330fd |
child | 12991:6d7e3d5463d8 |
comparison
equal
deleted
inserted
replaced
12976:a187600ec7d6 | 12977:74b9e05af71e |
---|---|
8 -- luacheck: ignore 212/self | 8 -- luacheck: ignore 212/self |
9 | 9 |
10 module:set_global(); | 10 module:set_global(); |
11 module:depends("admin_socket"); | 11 module:depends("admin_socket"); |
12 | 12 |
13 local hostmanager = require "core.hostmanager"; | 13 local hostmanager = require "prosody.core.hostmanager"; |
14 local modulemanager = require "core.modulemanager"; | 14 local modulemanager = require "prosody.core.modulemanager"; |
15 local s2smanager = require "core.s2smanager"; | 15 local s2smanager = require "prosody.core.s2smanager"; |
16 local portmanager = require "core.portmanager"; | 16 local portmanager = require "prosody.core.portmanager"; |
17 local helpers = require "util.helpers"; | 17 local helpers = require "prosody.util.helpers"; |
18 local server = require "net.server"; | 18 local server = require "prosody.net.server"; |
19 local st = require "util.stanza"; | 19 local st = require "prosody.util.stanza"; |
20 | 20 |
21 local _G = _G; | 21 local _G = _G; |
22 | 22 |
23 local prosody = _G.prosody; | 23 local prosody = _G.prosody; |
24 | 24 |
25 local unpack = table.unpack; | 25 local unpack = table.unpack; |
26 local iterators = require "util.iterators"; | 26 local iterators = require "prosody.util.iterators"; |
27 local keys, values = iterators.keys, iterators.values; | 27 local keys, values = iterators.keys, iterators.values; |
28 local jid_bare, jid_split, jid_join, jid_resource = import("util.jid", "bare", "prepped_split", "join", "resource"); | 28 local jid_bare, jid_split, jid_join, jid_resource = import("prosody.util.jid", "bare", "prepped_split", "join", "resource"); |
29 local set, array = require "util.set", require "util.array"; | 29 local set, array = require "prosody.util.set", require "prosody.util.array"; |
30 local cert_verify_identity = require "util.x509".verify_identity; | 30 local cert_verify_identity = require "prosody.util.x509".verify_identity; |
31 local envload = require "util.envload".envload; | 31 local envload = require "prosody.util.envload".envload; |
32 local envloadfile = require "util.envload".envloadfile; | 32 local envloadfile = require "prosody.util.envload".envloadfile; |
33 local has_pposix, pposix = pcall(require, "util.pposix"); | 33 local has_pposix, pposix = pcall(require, "prosody.util.pposix"); |
34 local async = require "util.async"; | 34 local async = require "prosody.util.async"; |
35 local serialization = require "util.serialization"; | 35 local serialization = require "prosody.util.serialization"; |
36 local serialize_config = serialization.new ({ fatal = false, unquoted = true}); | 36 local serialize_config = serialization.new ({ fatal = false, unquoted = true}); |
37 local time = require "util.time"; | 37 local time = require "prosody.util.time"; |
38 local promise = require "util.promise"; | 38 local promise = require "prosody.util.promise"; |
39 local logger = require "util.logger"; | 39 local logger = require "prosody.util.logger"; |
40 | 40 |
41 local t_insert = table.insert; | 41 local t_insert = table.insert; |
42 local t_concat = table.concat; | 42 local t_concat = table.concat; |
43 | 43 |
44 local format_number = require "util.human.units".format; | 44 local format_number = require "prosody.util.human.units".format; |
45 local format_table = require "util.human.io".table; | 45 local format_table = require "prosody.util.human.io".table; |
46 | 46 |
47 local function capitalize(s) | 47 local function capitalize(s) |
48 if not s then return end | 48 if not s then return end |
49 return (s:gsub("^%a", string.upper):gsub("_", " ")); | 49 return (s:gsub("^%a", string.upper):gsub("_", " ")); |
50 end | 50 end |
694 end | 694 end |
695 end | 695 end |
696 | 696 |
697 def_env.config = {}; | 697 def_env.config = {}; |
698 function def_env.config:load(filename, format) | 698 function def_env.config:load(filename, format) |
699 local config_load = require "core.configmanager".load; | 699 local config_load = require "prosody.core.configmanager".load; |
700 local ok, err = config_load(filename, format); | 700 local ok, err = config_load(filename, format); |
701 if not ok then | 701 if not ok then |
702 return false, err or "Unknown error loading config"; | 702 return false, err or "Unknown error loading config"; |
703 end | 703 end |
704 return true, "Config loaded"; | 704 return true, "Config loaded"; |
706 | 706 |
707 function def_env.config:get(host, key) | 707 function def_env.config:get(host, key) |
708 if key == nil then | 708 if key == nil then |
709 host, key = "*", host; | 709 host, key = "*", host; |
710 end | 710 end |
711 local config_get = require "core.configmanager".get | 711 local config_get = require "prosody.core.configmanager".get |
712 return true, serialize_config(config_get(host, key)); | 712 return true, serialize_config(config_get(host, key)); |
713 end | 713 end |
714 | 714 |
715 function def_env.config:reload() | 715 function def_env.config:reload() |
716 local ok, err = prosody.reload_config(); | 716 local ok, err = prosody.reload_config(); |
1504 else | 1504 else |
1505 return true, ("%d out of %d affiliation%s listed"):format(displayed, total, total ~= 1 and "s" or "") | 1505 return true, ("%d out of %d affiliation%s listed"):format(displayed, total, total ~= 1 and "s" or "") |
1506 end | 1506 end |
1507 end | 1507 end |
1508 | 1508 |
1509 local um = require"core.usermanager"; | 1509 local um = require"prosody.core.usermanager"; |
1510 | 1510 |
1511 def_env.user = {}; | 1511 def_env.user = {}; |
1512 function def_env.user:create(jid, password, role) | 1512 function def_env.user:create(jid, password, role) |
1513 local username, host = jid_split(jid); | 1513 local username, host = jid_split(jid); |
1514 if not prosody.hosts[host] then | 1514 if not prosody.hosts[host] then |
1675 return true, "Showing "..(pat and (matches.." of ") or "all " )..total.." users"; | 1675 return true, "Showing "..(pat and (matches.." of ") or "all " )..total.." users"; |
1676 end | 1676 end |
1677 | 1677 |
1678 def_env.xmpp = {}; | 1678 def_env.xmpp = {}; |
1679 | 1679 |
1680 local new_id = require "util.id".medium; | 1680 local new_id = require "prosody.util.id".medium; |
1681 function def_env.xmpp:ping(localhost, remotehost, timeout) | 1681 function def_env.xmpp:ping(localhost, remotehost, timeout) |
1682 localhost = select(2, jid_split(localhost)); | 1682 localhost = select(2, jid_split(localhost)); |
1683 remotehost = select(2, jid_split(remotehost)); | 1683 remotehost = select(2, jid_split(remotehost)); |
1684 if not localhost then | 1684 if not localhost then |
1685 return nil, "Invalid sender hostname"; | 1685 return nil, "Invalid sender hostname"; |
1727 return ("pong from %s on %s in %gs"):format(pong.stanza.attr.from, pong.origin.id, time.now() - time_start); | 1727 return ("pong from %s on %s in %gs"):format(pong.stanza.attr.from, pong.origin.id, time.now() - time_start); |
1728 end); | 1728 end); |
1729 end | 1729 end |
1730 | 1730 |
1731 def_env.dns = {}; | 1731 def_env.dns = {}; |
1732 local adns = require"net.adns"; | 1732 local adns = require"prosody.net.adns"; |
1733 | 1733 |
1734 local function get_resolver(session) | 1734 local function get_resolver(session) |
1735 local resolver = session.dns_resolver; | 1735 local resolver = session.dns_resolver; |
1736 if not resolver then | 1736 if not resolver then |
1737 resolver = adns.resolver(); | 1737 resolver = adns.resolver(); |
1870 | 1870 |
1871 function def_env.debug:events(host, event) | 1871 function def_env.debug:events(host, event) |
1872 local events_obj; | 1872 local events_obj; |
1873 if host and host ~= "*" then | 1873 if host and host ~= "*" then |
1874 if host == "http" then | 1874 if host == "http" then |
1875 events_obj = require "net.http.server"._events; | 1875 events_obj = require "prosody.net.http.server"._events; |
1876 elseif not prosody.hosts[host] then | 1876 elseif not prosody.hosts[host] then |
1877 return false, "Unknown host: "..host; | 1877 return false, "Unknown host: "..host; |
1878 else | 1878 else |
1879 events_obj = prosody.hosts[host].events; | 1879 events_obj = prosody.hosts[host].events; |
1880 end | 1880 end |
1884 return true, helpers.show_events(events_obj, event); | 1884 return true, helpers.show_events(events_obj, event); |
1885 end | 1885 end |
1886 | 1886 |
1887 function def_env.debug:timers() | 1887 function def_env.debug:timers() |
1888 local print = self.session.print; | 1888 local print = self.session.print; |
1889 local add_task = require"util.timer".add_task; | 1889 local add_task = require"prosody.util.timer".add_task; |
1890 local h, params = add_task.h, add_task.params; | 1890 local h, params = add_task.h, add_task.params; |
1891 local function normalize_time(t) | 1891 local function normalize_time(t) |
1892 return t; | 1892 return t; |
1893 end | 1893 end |
1894 local function format_time(t) | 1894 local function format_time(t) |
2181 -- the next sample and so on. | 2181 -- the next sample and so on. |
2182 return setmetatable({ session = self.session, stats = true, now = time.now() }, stats_mt); | 2182 return setmetatable({ session = self.session, stats = true, now = time.now() }, stats_mt); |
2183 end | 2183 end |
2184 | 2184 |
2185 function def_env.stats:show(name_filter) | 2185 function def_env.stats:show(name_filter) |
2186 local statsman = require "core.statsmanager" | 2186 local statsman = require "prosody.core.statsmanager" |
2187 local collect = statsman.collect | 2187 local collect = statsman.collect |
2188 if collect then | 2188 if collect then |
2189 -- force collection if in manual mode | 2189 -- force collection if in manual mode |
2190 collect() | 2190 collect() |
2191 end | 2191 end |