Software /
code /
prosody
Comparison
plugins/mod_admin_telnet.lua @ 9405:86e3e37f25ff
mod_admin_telnet: Use prosody.hosts to be more explicit and avoid name clash with 'hosts' arguments [luacheck]
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 30 Sep 2018 14:33:42 +0200 |
parent | 9404:f40b0cd41a87 |
child | 9406:7f277975768d |
comparison
equal
deleted
inserted
replaced
9404:f40b0cd41a87 | 9405:86e3e37f25ff |
---|---|
16 local helpers = require "util.helpers"; | 16 local helpers = require "util.helpers"; |
17 | 17 |
18 local _G = _G; | 18 local _G = _G; |
19 | 19 |
20 local prosody = _G.prosody; | 20 local prosody = _G.prosody; |
21 local hosts = prosody.hosts; | |
22 | 21 |
23 local console_listener = { default_port = 5582; default_mode = "*a"; interface = "127.0.0.1" }; | 22 local console_listener = { default_port = 5582; default_mode = "*a"; interface = "127.0.0.1" }; |
24 | 23 |
25 local iterators = require "util.iterators"; | 24 local iterators = require "util.iterators"; |
26 local keys, values = iterators.keys, iterators.values; | 25 local keys, values = iterators.keys, iterators.values; |
946 end; | 945 end; |
947 }; | 946 }; |
948 | 947 |
949 local function check_muc(jid) | 948 local function check_muc(jid) |
950 local room_name, host = jid_split(jid); | 949 local room_name, host = jid_split(jid); |
951 if not hosts[host] then | 950 if not prosody.hosts[host] then |
952 return nil, "No such host: "..host; | 951 return nil, "No such host: "..host; |
953 elseif not hosts[host].modules.muc then | 952 elseif not prosody.hosts[host].modules.muc then |
954 return nil, "Host '"..host.."' is not a MUC service"; | 953 return nil, "Host '"..host.."' is not a MUC service"; |
955 end | 954 end |
956 return room_name, host; | 955 return room_name, host; |
957 end | 956 end |
958 | 957 |
961 if not room_name then | 960 if not room_name then |
962 return room_name, host; | 961 return room_name, host; |
963 end | 962 end |
964 if not room_name then return nil, host end | 963 if not room_name then return nil, host end |
965 if config ~= nil and type(config) ~= "table" then return nil, "Config must be a table"; end | 964 if config ~= nil and type(config) ~= "table" then return nil, "Config must be a table"; end |
966 if hosts[host].modules.muc.get_room_from_jid(room_jid) then return nil, "Room exists already" end | 965 if prosody.hosts[host].modules.muc.get_room_from_jid(room_jid) then return nil, "Room exists already" end |
967 return hosts[host].modules.muc.create_room(room_jid, config); | 966 return prosody.hosts[host].modules.muc.create_room(room_jid, config); |
968 end | 967 end |
969 | 968 |
970 function def_env.muc:room(room_jid) | 969 function def_env.muc:room(room_jid) |
971 local room_name, host = check_muc(room_jid); | 970 local room_name, host = check_muc(room_jid); |
972 if not room_name then | 971 if not room_name then |
973 return room_name, host; | 972 return room_name, host; |
974 end | 973 end |
975 local room_obj = hosts[host].modules.muc.get_room_from_jid(room_jid); | 974 local room_obj = prosody.hosts[host].modules.muc.get_room_from_jid(room_jid); |
976 if not room_obj then | 975 if not room_obj then |
977 return nil, "No such room: "..room_jid; | 976 return nil, "No such room: "..room_jid; |
978 end | 977 end |
979 return setmetatable({ room = room_obj }, console_room_mt); | 978 return setmetatable({ room = room_obj }, console_room_mt); |
980 end | 979 end |
981 | 980 |
982 function def_env.muc:list(host) | 981 function def_env.muc:list(host) |
983 local host_session = hosts[host]; | 982 local host_session = prosody.hosts[host]; |
984 if not host_session or not host_session.modules.muc then | 983 if not host_session or not host_session.modules.muc then |
985 return nil, "Please supply the address of a local MUC component"; | 984 return nil, "Please supply the address of a local MUC component"; |
986 end | 985 end |
987 local print = self.session.print; | 986 local print = self.session.print; |
988 local c = 0; | 987 local c = 0; |
996 local um = require"core.usermanager"; | 995 local um = require"core.usermanager"; |
997 | 996 |
998 def_env.user = {}; | 997 def_env.user = {}; |
999 function def_env.user:create(jid, password) | 998 function def_env.user:create(jid, password) |
1000 local username, host = jid_split(jid); | 999 local username, host = jid_split(jid); |
1001 if not hosts[host] then | 1000 if not prosody.hosts[host] then |
1002 return nil, "No such host: "..host; | 1001 return nil, "No such host: "..host; |
1003 elseif um.user_exists(username, host) then | 1002 elseif um.user_exists(username, host) then |
1004 return nil, "User exists"; | 1003 return nil, "User exists"; |
1005 end | 1004 end |
1006 local ok, err = um.create_user(username, password, host); | 1005 local ok, err = um.create_user(username, password, host); |
1011 end | 1010 end |
1012 end | 1011 end |
1013 | 1012 |
1014 function def_env.user:delete(jid) | 1013 function def_env.user:delete(jid) |
1015 local username, host = jid_split(jid); | 1014 local username, host = jid_split(jid); |
1016 if not hosts[host] then | 1015 if not prosody.hosts[host] then |
1017 return nil, "No such host: "..host; | 1016 return nil, "No such host: "..host; |
1018 elseif not um.user_exists(username, host) then | 1017 elseif not um.user_exists(username, host) then |
1019 return nil, "No such user"; | 1018 return nil, "No such user"; |
1020 end | 1019 end |
1021 local ok, err = um.delete_user(username, host); | 1020 local ok, err = um.delete_user(username, host); |
1026 end | 1025 end |
1027 end | 1026 end |
1028 | 1027 |
1029 function def_env.user:password(jid, password) | 1028 function def_env.user:password(jid, password) |
1030 local username, host = jid_split(jid); | 1029 local username, host = jid_split(jid); |
1031 if not hosts[host] then | 1030 if not prosody.hosts[host] then |
1032 return nil, "No such host: "..host; | 1031 return nil, "No such host: "..host; |
1033 elseif not um.user_exists(username, host) then | 1032 elseif not um.user_exists(username, host) then |
1034 return nil, "No such user"; | 1033 return nil, "No such user"; |
1035 end | 1034 end |
1036 local ok, err = um.set_password(username, password, host, nil); | 1035 local ok, err = um.set_password(username, password, host, nil); |
1042 end | 1041 end |
1043 | 1042 |
1044 function def_env.user:list(host, pat) | 1043 function def_env.user:list(host, pat) |
1045 if not host then | 1044 if not host then |
1046 return nil, "No host given"; | 1045 return nil, "No host given"; |
1047 elseif not hosts[host] then | 1046 elseif not prosody.hosts[host] then |
1048 return nil, "No such host"; | 1047 return nil, "No such host"; |
1049 end | 1048 end |
1050 local print = self.session.print; | 1049 local print = self.session.print; |
1051 local total, matches = 0, 0; | 1050 local total, matches = 0, 0; |
1052 for user in um.users(host) do | 1051 for user in um.users(host) do |
1061 | 1060 |
1062 def_env.xmpp = {}; | 1061 def_env.xmpp = {}; |
1063 | 1062 |
1064 local st = require "util.stanza"; | 1063 local st = require "util.stanza"; |
1065 function def_env.xmpp:ping(localhost, remotehost) | 1064 function def_env.xmpp:ping(localhost, remotehost) |
1066 if hosts[localhost] then | 1065 if prosody.hosts[localhost] then |
1067 module:send(st.iq{ from=localhost, to=remotehost, type="get", id="ping" } | 1066 module:send(st.iq{ from=localhost, to=remotehost, type="get", id="ping" } |
1068 :tag("ping", {xmlns="urn:xmpp:ping"}), hosts[localhost]); | 1067 :tag("ping", {xmlns="urn:xmpp:ping"}), prosody.hosts[localhost]); |
1069 return true, "Sent ping"; | 1068 return true, "Sent ping"; |
1070 else | 1069 else |
1071 return nil, "No such host"; | 1070 return nil, "No such host"; |
1072 end | 1071 end |
1073 end | 1072 end |
1141 end | 1140 end |
1142 | 1141 |
1143 function def_env.debug:events(host, event) | 1142 function def_env.debug:events(host, event) |
1144 local events_obj; | 1143 local events_obj; |
1145 if host and host ~= "*" then | 1144 if host and host ~= "*" then |
1146 if not hosts[host] then | 1145 if not prosody.hosts[host] then |
1147 return false, "Unknown host: "..host; | 1146 return false, "Unknown host: "..host; |
1148 end | 1147 end |
1149 events_obj = hosts[host].events; | 1148 events_obj = prosody.hosts[host].events; |
1150 else | 1149 else |
1151 events_obj = prosody.events; | 1150 events_obj = prosody.events; |
1152 end | 1151 end |
1153 return true, helpers.show_events(events_obj, event); | 1152 return true, helpers.show_events(events_obj, event); |
1154 end | 1153 end |