Software /
code /
prosody
Annotate
util/prosodyctl.lua @ 11046:64713f21ff0e
util.dbuffer: Simplify test case
An earlier theory involved the bug being related to collapsing multiple
items, so it exercised that too.
Also correct the comment, it referred to the space in "hello world" in
an earlier version before the test string was changed to "foobar", which
was what was tested in a REPL
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Mon, 24 Aug 2020 17:28:48 +0200 |
parent | 10871:e5dee71d0ebb |
child | 11132:287d0d80aa57 |
rev | line source |
---|---|
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1515
diff
changeset
|
1 -- Prosody IM |
2923
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2796
diff
changeset
|
2 -- Copyright (C) 2008-2010 Matthew Wild |
b7049746bd29
Update copyright headers for 2010
Matthew Wild <mwild1@gmail.com>
parents:
2796
diff
changeset
|
3 -- Copyright (C) 2008-2010 Waqas Hussain |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
4 -- |
1522
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1515
diff
changeset
|
5 -- This project is MIT/X11 licensed. Please see the |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1515
diff
changeset
|
6 -- COPYING file in the source package for more information. |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1515
diff
changeset
|
7 -- |
569d58d21612
Add copyright header to those files missing one
Matthew Wild <mwild1@gmail.com>
parents:
1515
diff
changeset
|
8 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 local config = require "core.configmanager"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 local encodings = require "util.encodings"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 local stringprep = encodings.stringprep; |
3771
428882c438bf
util.prosodyctl: Initialize storagemanager on hosts we modify
Matthew Wild <mwild1@gmail.com>
parents:
3711
diff
changeset
|
13 local storagemanager = require "core.storagemanager"; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
14 local usermanager = require "core.usermanager"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 local signal = require "util.signal"; |
3627
9e62937c9757
prosodyctl, util.prosodyctl: Show error when mod_posix is not enabled and an attempt is made to query Prosody's status (thanks stever)
Matthew Wild <mwild1@gmail.com>
parents:
3307
diff
changeset
|
16 local set = require "util.set"; |
2794
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
17 local lfs = require "lfs"; |
4485
abfd27b59fa8
util.prosodyctl: Add getline() and show_prompt()
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
18 local type = type; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
19 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 local nodeprep, nameprep = stringprep.nodeprep, stringprep.nameprep; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
21 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
22 local io, os = io, os; |
4142
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
23 local print = print; |
7259
d8300985f2bb
net.websocket.frames, util.datetime, util.json, util.prosodyctl, util.rfc6724: Remove unused variables [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
6777
diff
changeset
|
24 local tonumber = tonumber; |
1130
442c87de8e2d
util.prosodyctl: Import CFG_SOURCEDIR from the global environment (thanks macaronyde!)
Matthew Wild <mwild1@gmail.com>
parents:
1123
diff
changeset
|
25 |
4142
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
26 local _G = _G; |
3294
89dd67cc3689
util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
27 local prosody = prosody; |
89dd67cc3689
util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
28 |
10871
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
29 local error_messages = setmetatable({ |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
30 ["invalid-username"] = "The given username is invalid in a Jabber ID"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
31 ["invalid-hostname"] = "The given hostname is invalid"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
32 ["no-password"] = "No password was supplied"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
33 ["no-such-user"] = "The given user does not exist on the server"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
34 ["no-such-host"] = "The given hostname does not exist in the config"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
35 ["unable-to-save-data"] = "Unable to store, perhaps you don't have permission?"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
36 ["no-pidfile"] = "There is no 'pidfile' option in the configuration file, see https://prosody.im/doc/prosodyctl#pidfile for help"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
37 ["invalid-pidfile"] = "The 'pidfile' option in the configuration file is not a string, see https://prosody.im/doc/prosodyctl#pidfile for help"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
38 ["no-posix"] = "The mod_posix module is not enabled in the Prosody config file, see https://prosody.im/doc/prosodyctl for more info"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
39 ["no-such-method"] = "This module has no commands"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
40 ["not-running"] = "Prosody is not running"; |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
41 }, { __index = function (_,k) return "Error: "..(tostring(k):gsub("%-", " "):gsub("^.", string.upper)); end }); |
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
42 |
4142
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
43 -- UI helpers |
10871
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
44 local show_message = require "util.human.io".printf; |
4142
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
45 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
46 local function show_usage(usage, desc) |
4142
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
47 print("Usage: ".._G.arg[0].." "..usage); |
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
48 if desc then |
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
49 print(" "..desc); |
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
50 end |
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
51 end |
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
52 |
10152
7e9c30eab11e
util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents:
10148
diff
changeset
|
53 local function show_module_configuration_help(mod_name) |
7e9c30eab11e
util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents:
10148
diff
changeset
|
54 print("Done.") |
7e9c30eab11e
util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents:
10148
diff
changeset
|
55 print("If you installed a prosody plugin, don't forget to add its name under the 'modules_enabled' section inside your configuration file.") |
7e9c30eab11e
util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents:
10148
diff
changeset
|
56 print("Depending on the module, there might be further configuration steps required.") |
7e9c30eab11e
util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents:
10148
diff
changeset
|
57 print("") |
7e9c30eab11e
util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents:
10148
diff
changeset
|
58 print("More info about: ") |
7e9c30eab11e
util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents:
10148
diff
changeset
|
59 print(" modules_enabled: https://prosody.im/doc/modules_enabled") |
7e9c30eab11e
util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents:
10148
diff
changeset
|
60 print(" "..mod_name..": https://modules.prosody.im/"..mod_name..".html") |
7e9c30eab11e
util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents:
10148
diff
changeset
|
61 end |
7e9c30eab11e
util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents:
10148
diff
changeset
|
62 |
4142
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
63 -- Server control |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
64 local function adduser(params) |
10367
649acbfbf7fe
util.prosodyctl: Enforce strict JID validation on user creation
Kim Alvefur <zash@zash.se>
parents:
10209
diff
changeset
|
65 local user, host, password = nodeprep(params.user, true), nameprep(params.host), params.password; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 if not user then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
67 return false, "invalid-username"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
68 elseif not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
69 return false, "invalid-hostname"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
70 end |
3294
89dd67cc3689
util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
71 |
4501
eacc93e23f21
util.prosodyctl: Fix variable name clash introduced in 55ef5d83d00a (thanks chris)
Matthew Wild <mwild1@gmail.com>
parents:
4499
diff
changeset
|
72 local host_session = prosody.hosts[host]; |
eacc93e23f21
util.prosodyctl: Fix variable name clash introduced in 55ef5d83d00a (thanks chris)
Matthew Wild <mwild1@gmail.com>
parents:
4499
diff
changeset
|
73 if not host_session then |
4499
55ef5d83d00a
util.prosodyctl: In the register command, check that the virtual exists before proceeding.
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
74 return false, "no-such-host"; |
55ef5d83d00a
util.prosodyctl: In the register command, check that the virtual exists before proceeding.
Kim Alvefur <zash@zash.se>
parents:
4335
diff
changeset
|
75 end |
5524
e9090966c803
util.prosodyctl: Initialize storagemanager on the host before initializing usermanager. This fixes brokenness when the auth provider opens the store on load (as they all do since eeea0eb2602a) (thanks nulani)
Matthew Wild <mwild1@gmail.com>
parents:
5379
diff
changeset
|
76 |
e9090966c803
util.prosodyctl: Initialize storagemanager on the host before initializing usermanager. This fixes brokenness when the auth provider opens the store on load (as they all do since eeea0eb2602a) (thanks nulani)
Matthew Wild <mwild1@gmail.com>
parents:
5379
diff
changeset
|
77 storagemanager.initialize_host(host); |
4501
eacc93e23f21
util.prosodyctl: Fix variable name clash introduced in 55ef5d83d00a (thanks chris)
Matthew Wild <mwild1@gmail.com>
parents:
4499
diff
changeset
|
78 local provider = host_session.users; |
3294
89dd67cc3689
util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
79 if not(provider) or provider.name == "null" then |
89dd67cc3689
util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
80 usermanager.initialize_host(host); |
89dd67cc3689
util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
81 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
82 |
3777
5ecbcef42ffb
mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents:
3771
diff
changeset
|
83 local ok, errmsg = usermanager.create_user(user, password, host); |
1123
da7ff11a03ee
util.prosodyctl: Return success status of usermanager.create_user()
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
84 if not ok then |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
85 return false, errmsg or "creating-user-failed"; |
1123
da7ff11a03ee
util.prosodyctl: Return success status of usermanager.create_user()
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
86 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
87 return true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
88 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
90 local function user_exists(params) |
7262
751a4832adb4
util.prosodyctl: Remove unused variable [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
7259
diff
changeset
|
91 local user, host = nodeprep(params.user), nameprep(params.host); |
5524
e9090966c803
util.prosodyctl: Initialize storagemanager on the host before initializing usermanager. This fixes brokenness when the auth provider opens the store on load (as they all do since eeea0eb2602a) (thanks nulani)
Matthew Wild <mwild1@gmail.com>
parents:
5379
diff
changeset
|
92 |
e9090966c803
util.prosodyctl: Initialize storagemanager on the host before initializing usermanager. This fixes brokenness when the auth provider opens the store on load (as they all do since eeea0eb2602a) (thanks nulani)
Matthew Wild <mwild1@gmail.com>
parents:
5379
diff
changeset
|
93 storagemanager.initialize_host(host); |
3711
2a1cfaf3ee61
util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
94 local provider = prosody.hosts[host].users; |
3294
89dd67cc3689
util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
95 if not(provider) or provider.name == "null" then |
3711
2a1cfaf3ee61
util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
96 usermanager.initialize_host(host); |
3294
89dd67cc3689
util.prosodyctl: Initialize the host's auth provider if necessary (thanks johnny, and all the other people whom this hindered :) )
Matthew Wild <mwild1@gmail.com>
parents:
2925
diff
changeset
|
97 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
98 |
3711
2a1cfaf3ee61
util.prosodyctl: Prep JIDs before checking whether they exist (thanks tja)
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
99 return usermanager.user_exists(user, host); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
102 local function passwd(params) |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
103 if not user_exists(params) then |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 return false, "no-such-user"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
106 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
107 return adduser(params); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
110 local function deluser(params) |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
111 if not user_exists(params) then |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 return false, "no-such-user"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
113 end |
5102
ae8a993b598d
util.prosodyctl: Use usermanager to delete users instead of unsetting their password
Kim Alvefur <zash@zash.se>
parents:
5023
diff
changeset
|
114 local user, host = nodeprep(params.user), nameprep(params.host); |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
115 |
5102
ae8a993b598d
util.prosodyctl: Use usermanager to delete users instead of unsetting their password
Kim Alvefur <zash@zash.se>
parents:
5023
diff
changeset
|
116 return usermanager.delete_user(user, host); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
117 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
118 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
119 local function getpid() |
5379
27de7cc94111
util.{prosodyctl,openssl}: More use of config sections removed
Kim Alvefur <zash@zash.se>
parents:
5102
diff
changeset
|
120 local pidfile = config.get("*", "pidfile"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
121 if not pidfile then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
122 return false, "no-pidfile"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
123 end |
6356
fb1535328ac7
prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents:
5524
diff
changeset
|
124 |
fb1535328ac7
prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents:
5524
diff
changeset
|
125 if type(pidfile) ~= "string" then |
fb1535328ac7
prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents:
5524
diff
changeset
|
126 return false, "invalid-pidfile"; |
fb1535328ac7
prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents:
5524
diff
changeset
|
127 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
128 |
8123
bd591c5fc1bf
util.prosodyctl: Resolve possibly relative pidfile path (fixes inconsistency with mod_posix)
Kim Alvefur <zash@zash.se>
parents:
7457
diff
changeset
|
129 pidfile = config.resolve_relative_path(prosody.paths.data, pidfile); |
bd591c5fc1bf
util.prosodyctl: Resolve possibly relative pidfile path (fixes inconsistency with mod_posix)
Kim Alvefur <zash@zash.se>
parents:
7457
diff
changeset
|
130 |
8883
3f975bbfec3b
util.prosodyctl: Rename variables for consistency (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
8668
diff
changeset
|
131 local modules_disabled = set.new(config.get("*", "modules_disabled")); |
3f975bbfec3b
util.prosodyctl: Rename variables for consistency (thanks Link Mauve)
Kim Alvefur <zash@zash.se>
parents:
8668
diff
changeset
|
132 if prosody.platform ~= "posix" or modules_disabled:contains("posix") then |
3627
9e62937c9757
prosodyctl, util.prosodyctl: Show error when mod_posix is not enabled and an attempt is made to query Prosody's status (thanks stever)
Matthew Wild <mwild1@gmail.com>
parents:
3307
diff
changeset
|
133 return false, "no-posix"; |
9e62937c9757
prosodyctl, util.prosodyctl: Show error when mod_posix is not enabled and an attempt is made to query Prosody's status (thanks stever)
Matthew Wild <mwild1@gmail.com>
parents:
3307
diff
changeset
|
134 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
135 |
2796
1e287badd033
prosodyctl: Use mode r+ for opening the file so 1) it fails if the file doesn't exist 2) we have write access to lock it
Matthew Wild <mwild1@gmail.com>
parents:
2794
diff
changeset
|
136 local file, err = io.open(pidfile, "r+"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
137 if not file then |
1515
9991329e6b67
util.prosodyctl: Fix undefined global access
Matthew Wild <mwild1@gmail.com>
parents:
1130
diff
changeset
|
138 return false, "pidfile-read-failed", err; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
139 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
140 |
10536
a469d2bcea96
util.prosodyctl: Silence luacheck warnings
Kim Alvefur <zash@zash.se>
parents:
10367
diff
changeset
|
141 local locked, err = lfs.lock(file, "w"); -- luacheck: ignore 211/err |
2794
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
142 if locked then |
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
143 file:close(); |
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
144 return false, "pidfile-not-locked"; |
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
145 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
146 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
147 local pid = tonumber(file:read("*a")); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
148 file:close(); |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
149 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
150 if not pid then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
151 return false, "invalid-pid"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
152 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
153 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
154 return true, pid; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
155 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
156 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
157 local function isrunning() |
10536
a469d2bcea96
util.prosodyctl: Silence luacheck warnings
Kim Alvefur <zash@zash.se>
parents:
10367
diff
changeset
|
158 local ok, pid, err = getpid(); -- luacheck: ignore 211/err |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
159 if not ok then |
2794
5f14cd94a563
util.prosodyctl: Report Prosody as not running if the pidfile isn't locked
Matthew Wild <mwild1@gmail.com>
parents:
1522
diff
changeset
|
160 if pid == "pidfile-read-failed" or pid == "pidfile-not-locked" then |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
161 -- Report as not running, since we can't open the pidfile |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
162 -- (it probably doesn't exist) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
163 return true, false; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
164 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
165 return ok, pid; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
166 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
167 return true, signal.kill(pid, 0) == 0; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
168 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
169 |
9781
161411a41377
util.prosodyctl: Allow passing path to Lua runtime to the start() function
Kim Alvefur <zash@zash.se>
parents:
8883
diff
changeset
|
170 local function start(source_dir, lua) |
161411a41377
util.prosodyctl: Allow passing path to Lua runtime to the start() function
Kim Alvefur <zash@zash.se>
parents:
8883
diff
changeset
|
171 lua = lua and lua .. " " or ""; |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
172 local ok, ret = isrunning(); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
173 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
174 return ok, ret; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
175 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
176 if ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
177 return false, "already-running"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
178 end |
8668
31c5abd49dfe
prosodyctl, util.prosodyctl: Pass source path as a parameter instead of global variable
Matthew Wild <mwild1@gmail.com>
parents:
8634
diff
changeset
|
179 if not source_dir then |
10627
88be11e9f9b9
util.prosodyctl: Pass command line flag to force daemonization on start
Kim Alvefur <zash@zash.se>
parents:
10536
diff
changeset
|
180 os.execute(lua .. "./prosody -D"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
181 else |
10627
88be11e9f9b9
util.prosodyctl: Pass command line flag to force daemonization on start
Kim Alvefur <zash@zash.se>
parents:
10536
diff
changeset
|
182 os.execute(lua .. source_dir.."/../../bin/prosody -D"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
183 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
184 return true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
185 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
186 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
187 local function stop() |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
188 local ok, ret = isrunning(); |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
189 if not ok then |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
190 return ok, ret; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
191 end |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
192 if not ret then |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
193 return false, "not-running"; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
194 end |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
195 |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
196 local ok, pid = getpid() |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
197 if not ok then return false, pid; end |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
198 |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
199 signal.kill(pid, signal.SIGTERM); |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
200 return true; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
201 end |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
202 |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
203 local function reload() |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
204 local ok, ret = isrunning(); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
205 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
206 return ok, ret; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
207 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
208 if not ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 return false, "not-running"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
211 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
212 local ok, pid = getpid() |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
213 if not ok then return false, pid; end |
6771
60957dd5b41b
util.{interpolation,prosodyctl,sql}: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
214 |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
215 signal.kill(pid, signal.SIGHUP); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
216 return true; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4142
diff
changeset
|
217 end |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4503
diff
changeset
|
218 |
10167
f343ed1f02fd
util.prosodyctl: Created the helper function get_path_custom_plugins
João Duarte <jvsDuarte08@gmail.com>
parents:
10158
diff
changeset
|
219 local function get_path_custom_plugins(plugin_paths) |
10191
395ce57dccdf
util.prosodyctl: Changed a comment
João Duarte <jvsDuarte08@gmail.com>
parents:
10189
diff
changeset
|
220 -- I'm considering that the custom plugins' path is the first one at prosody.paths.plugins |
10167
f343ed1f02fd
util.prosodyctl: Created the helper function get_path_custom_plugins
João Duarte <jvsDuarte08@gmail.com>
parents:
10158
diff
changeset
|
221 -- luacheck: ignore 512 |
f343ed1f02fd
util.prosodyctl: Created the helper function get_path_custom_plugins
João Duarte <jvsDuarte08@gmail.com>
parents:
10158
diff
changeset
|
222 for path in plugin_paths:gmatch("[^;]+") do |
10180
152604d54732
util.prosodyctl: Added the check_flags function
João Duarte <jvsDuarte08@gmail.com>
parents:
10167
diff
changeset
|
223 return path; |
10167
f343ed1f02fd
util.prosodyctl: Created the helper function get_path_custom_plugins
João Duarte <jvsDuarte08@gmail.com>
parents:
10158
diff
changeset
|
224 end |
f343ed1f02fd
util.prosodyctl: Created the helper function get_path_custom_plugins
João Duarte <jvsDuarte08@gmail.com>
parents:
10158
diff
changeset
|
225 end |
f343ed1f02fd
util.prosodyctl: Created the helper function get_path_custom_plugins
João Duarte <jvsDuarte08@gmail.com>
parents:
10158
diff
changeset
|
226 |
10209
e6ba8bb91905
util/prosodyctl: call_luarocks now sets a directory variable itself
João Duarte <jvsDuarte08@gmail.com>
parents:
10208
diff
changeset
|
227 local function call_luarocks(mod, operation) |
e6ba8bb91905
util/prosodyctl: call_luarocks now sets a directory variable itself
João Duarte <jvsDuarte08@gmail.com>
parents:
10208
diff
changeset
|
228 local dir = get_path_custom_plugins(prosody.paths.plugins); |
10183
5eba710e33f9
util.prosodyctl: Function now differentiates its output, depending if it is being called by install or remove
João Duarte <jvsDuarte08@gmail.com>
parents:
10181
diff
changeset
|
229 if operation == "install" then |
10181
c7d5cd766533
util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents:
10180
diff
changeset
|
230 show_message("Installing %s at %s", mod, dir); |
10183
5eba710e33f9
util.prosodyctl: Function now differentiates its output, depending if it is being called by install or remove
João Duarte <jvsDuarte08@gmail.com>
parents:
10181
diff
changeset
|
231 elseif operation == "remove" then |
5eba710e33f9
util.prosodyctl: Function now differentiates its output, depending if it is being called by install or remove
João Duarte <jvsDuarte08@gmail.com>
parents:
10181
diff
changeset
|
232 show_message("Removing %s from %s", mod, dir); |
5eba710e33f9
util.prosodyctl: Function now differentiates its output, depending if it is being called by install or remove
João Duarte <jvsDuarte08@gmail.com>
parents:
10181
diff
changeset
|
233 end |
10185
02d8f475a96d
util.prosodyctl: call_luarocks function is now compatible with the list command
João Duarte <jvsDuarte08@gmail.com>
parents:
10183
diff
changeset
|
234 if operation == "list" then |
02d8f475a96d
util.prosodyctl: call_luarocks function is now compatible with the list command
João Duarte <jvsDuarte08@gmail.com>
parents:
10183
diff
changeset
|
235 os.execute("luarocks list --tree='"..dir.."'") |
02d8f475a96d
util.prosodyctl: call_luarocks function is now compatible with the list command
João Duarte <jvsDuarte08@gmail.com>
parents:
10183
diff
changeset
|
236 else |
02d8f475a96d
util.prosodyctl: call_luarocks function is now compatible with the list command
João Duarte <jvsDuarte08@gmail.com>
parents:
10183
diff
changeset
|
237 os.execute("luarocks --tree='"..dir.."' --server='http://localhost/' "..operation.." "..mod); |
02d8f475a96d
util.prosodyctl: call_luarocks function is now compatible with the list command
João Duarte <jvsDuarte08@gmail.com>
parents:
10183
diff
changeset
|
238 end |
10183
5eba710e33f9
util.prosodyctl: Function now differentiates its output, depending if it is being called by install or remove
João Duarte <jvsDuarte08@gmail.com>
parents:
10181
diff
changeset
|
239 if operation == "install" then |
10181
c7d5cd766533
util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents:
10180
diff
changeset
|
240 show_module_configuration_help(mod); |
10183
5eba710e33f9
util.prosodyctl: Function now differentiates its output, depending if it is being called by install or remove
João Duarte <jvsDuarte08@gmail.com>
parents:
10181
diff
changeset
|
241 end |
10181
c7d5cd766533
util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents:
10180
diff
changeset
|
242 end |
c7d5cd766533
util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents:
10180
diff
changeset
|
243 |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
244 return { |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
245 show_message = show_message; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
246 show_warning = show_message; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
247 show_usage = show_usage; |
10152
7e9c30eab11e
util.prosodyctl: Added the show_module_configuration_help function
João Duarte <jvsDuarte08@gmail.com>
parents:
10148
diff
changeset
|
248 show_module_configuration_help = show_module_configuration_help; |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
249 adduser = adduser; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
250 user_exists = user_exists; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
251 passwd = passwd; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
252 deluser = deluser; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
253 getpid = getpid; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
254 isrunning = isrunning; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
255 start = start; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
256 stop = stop; |
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
257 reload = reload; |
10167
f343ed1f02fd
util.prosodyctl: Created the helper function get_path_custom_plugins
João Duarte <jvsDuarte08@gmail.com>
parents:
10158
diff
changeset
|
258 get_path_custom_plugins = get_path_custom_plugins; |
10181
c7d5cd766533
util.prosodyctl: Added the call_luarocks function
João Duarte <jvsDuarte08@gmail.com>
parents:
10180
diff
changeset
|
259 call_luarocks = call_luarocks; |
10871
e5dee71d0ebb
prosodyctl+util.prosodyctl.*: Start breaking up the ever-growing prosodyctl
Matthew Wild <mwild1@gmail.com>
parents:
10722
diff
changeset
|
260 error_messages = error_messages; |
6777
5de6b93d0190
util.*: Remove use of module() function, make all module functions local and return them in a table at the end
Kim Alvefur <zash@zash.se>
parents:
6771
diff
changeset
|
261 }; |