Software /
code /
prosody
Annotate
prosodyctl @ 5134:43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Wed, 19 Sep 2012 12:39:21 +0100 |
parent | 5101:a94c43cad081 |
child | 5138:7dc57dfaebbe |
child | 5142:3221746f4769 |
rev | line source |
---|---|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env lua |
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1501
diff
changeset
|
2 -- Prosody IM |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
3 -- Copyright (C) 2008-2010 Matthew Wild |
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
4 -- Copyright (C) 2008-2010 Waqas Hussain |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 -- |
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 -- prosodyctl - command-line controller for Prosody XMPP server |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 -- Will be modified by configure script if run -- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 |
3741
f7dd583d99b4
prosodyctl: Read PROSODY_SRCDIR and PROSODY_PLUGINDIR environment variables, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3739
diff
changeset
|
14 CFG_SOURCEDIR=os.getenv("PROSODY_SRCDIR"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR"); |
3741
f7dd583d99b4
prosodyctl: Read PROSODY_SRCDIR and PROSODY_PLUGINDIR environment variables, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3739
diff
changeset
|
16 CFG_PLUGINDIR=os.getenv("PROSODY_PLUGINDIR"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 CFG_DATADIR=os.getenv("PROSODY_DATADIR"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
19 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
3999
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
21 local function is_relative(path) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
22 local path_sep = package.config:sub(1,1); |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
23 return ((path_sep == "/" and path:sub(1,1) ~= "/") |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
24 or (path_sep == "\\" and (path:sub(1,1) ~= "/" and path:sub(2,3) ~= ":\\"))) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
25 end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
26 |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
27 -- Tell Lua where to find our libraries |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 if CFG_SOURCEDIR then |
3999
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
29 local function filter_relative_paths(path) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
30 if is_relative(path) then return ""; end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
31 end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
32 local function sanitise_paths(paths) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
33 return (paths:gsub("[^;]+;?", filter_relative_paths):gsub(";;+", ";")); |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
34 end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
35 package.path = sanitise_paths(CFG_SOURCEDIR.."/?.lua;"..package.path); |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
36 package.cpath = sanitise_paths(CFG_SOURCEDIR.."/?.so;"..package.cpath); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
39 -- Substitute ~ with path to home directory in data path |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 if CFG_DATADIR then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 if os.getenv("HOME") then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 CFG_DATADIR = CFG_DATADIR:gsub("^~", os.getenv("HOME")); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
3013
518e3f6f9946
prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents:
2706
diff
changeset
|
46 -- Global 'prosody' object |
3998
009d1ad84b49
prosody, prosodyctl: Create prosody object as a local before exporting as a global
Matthew Wild <mwild1@gmail.com>
parents:
3904
diff
changeset
|
47 local prosody = { |
3773
2e15808243f3
prosodyctl: Add dummy lock/unlock_globals() until util.startup comes along
Matthew Wild <mwild1@gmail.com>
parents:
3742
diff
changeset
|
48 hosts = {}; |
2e15808243f3
prosodyctl: Add dummy lock/unlock_globals() until util.startup comes along
Matthew Wild <mwild1@gmail.com>
parents:
3742
diff
changeset
|
49 events = require "util.events".new(); |
2e15808243f3
prosodyctl: Add dummy lock/unlock_globals() until util.startup comes along
Matthew Wild <mwild1@gmail.com>
parents:
3742
diff
changeset
|
50 platform = "posix"; |
2e15808243f3
prosodyctl: Add dummy lock/unlock_globals() until util.startup comes along
Matthew Wild <mwild1@gmail.com>
parents:
3742
diff
changeset
|
51 lock_globals = function () end; |
2e15808243f3
prosodyctl: Add dummy lock/unlock_globals() until util.startup comes along
Matthew Wild <mwild1@gmail.com>
parents:
3742
diff
changeset
|
52 unlock_globals = function () end; |
5134
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
53 installed = CFG_SOURCEDIR ~= nil; |
3013
518e3f6f9946
prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents:
2706
diff
changeset
|
54 }; |
3998
009d1ad84b49
prosody, prosodyctl: Create prosody object as a local before exporting as a global
Matthew Wild <mwild1@gmail.com>
parents:
3904
diff
changeset
|
55 _G.prosody = prosody; |
3013
518e3f6f9946
prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents:
2706
diff
changeset
|
56 |
3904
f93163081b3c
prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
57 local dependencies = require "util.dependencies"; |
f93163081b3c
prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
58 if not dependencies.check_dependencies() then |
f93163081b3c
prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
59 os.exit(1); |
f93163081b3c
prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
60 end |
f93163081b3c
prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
61 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
62 config = require "core.configmanager" |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 do |
3739
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
65 local filenames = {}; |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
66 |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
67 local filename; |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
68 if arg[1] == "--config" and arg[2] then |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
69 table.insert(filenames, arg[2]); |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
70 table.remove(arg, 1); table.remove(arg, 1); |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
71 if CFG_CONFIGDIR then |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
72 table.insert(filenames, CFG_CONFIGDIR.."/"..arg[2]); |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
73 end |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
74 else |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
75 for _, format in ipairs(config.parsers()) do |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
76 table.insert(filenames, (CFG_CONFIGDIR or ".").."/prosody.cfg."..format); |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
77 end |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
78 end |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
79 for _,_filename in ipairs(filenames) do |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
80 filename = _filename; |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
81 local file = io.open(filename); |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
82 if file then |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
83 file:close(); |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
84 CFG_CONFIGDIR = filename:match("^(.*)[\\/][^\\/]*$"); |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
85 break; |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
86 end |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
87 end |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
88 local ok, level, err = config.load(filename); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
89 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
90 print("\n"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
91 print("**************************"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
92 if level == "parser" then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 print("A problem occured while reading the config file "..(CFG_CONFIGDIR or ".").."/prosody.cfg.lua"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 local err_line, err_message = tostring(err):match("%[string .-%]:(%d*): (.*)"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 print("Error"..(err_line and (" on line "..err_line) or "")..": "..(err_message or tostring(err))); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 print(""); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 elseif level == "file" then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
98 print("Prosody was unable to find the configuration file."); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
99 print("We looked for: "..(CFG_CONFIGDIR or ".").."/prosody.cfg.lua"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 print("A sample config file is included in the Prosody download called prosody.cfg.lua.dist"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 print("Copy or rename it to prosody.cfg.lua and edit as necessary."); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 print("More help on configuring Prosody can be found at http://prosody.im/doc/configure"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
104 print("Good luck!"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
105 print("**************************"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 print(""); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
107 os.exit(1); |
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 end |
3339
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
110 local original_logging_config = config.get("*", "core", "log"); |
3338
d50b6b3efad1
prosodyctl: Force log output always to the console instead of using the config, which avoids creating log files as the wrong user
Matthew Wild <mwild1@gmail.com>
parents:
3337
diff
changeset
|
111 config.set("*", "core", "log", { { levels = { min="info" }, to = "console" } }); |
d50b6b3efad1
prosodyctl: Force log output always to the console instead of using the config, which avoids creating log files as the wrong user
Matthew Wild <mwild1@gmail.com>
parents:
3337
diff
changeset
|
112 |
4095
6ad7ed619d37
prosodyctl: Instead of calling datamanager.set_path(), just ensure prosody.paths.data always contains the correct value (including config)
Matthew Wild <mwild1@gmail.com>
parents:
3999
diff
changeset
|
113 local data_path = config.get("*", "core", "data_path") or CFG_DATADIR or "data"; |
4158
14581c3f33bd
prosodyctl: Support for plugin_paths config option
Matthew Wild <mwild1@gmail.com>
parents:
4142
diff
changeset
|
114 local custom_plugin_paths = config.get("*", "core", "plugin_paths"); |
14581c3f33bd
prosodyctl: Support for plugin_paths config option
Matthew Wild <mwild1@gmail.com>
parents:
4142
diff
changeset
|
115 if custom_plugin_paths then |
4167
9c60cc8dc142
prosody, prosodyctl: Use plugin_paths in addition to, not instead of, the default plugin path
Matthew Wild <mwild1@gmail.com>
parents:
4158
diff
changeset
|
116 local path_sep = package.config:sub(3,3); |
9c60cc8dc142
prosody, prosodyctl: Use plugin_paths in addition to, not instead of, the default plugin path
Matthew Wild <mwild1@gmail.com>
parents:
4158
diff
changeset
|
117 -- path1;path2;path3;defaultpath... |
9c60cc8dc142
prosody, prosodyctl: Use plugin_paths in addition to, not instead of, the default plugin path
Matthew Wild <mwild1@gmail.com>
parents:
4158
diff
changeset
|
118 CFG_PLUGINDIR = table.concat(custom_plugin_paths, path_sep)..path_sep..(CFG_PLUGINDIR or "plugins"); |
4158
14581c3f33bd
prosodyctl: Support for plugin_paths config option
Matthew Wild <mwild1@gmail.com>
parents:
4142
diff
changeset
|
119 end |
4095
6ad7ed619d37
prosodyctl: Instead of calling datamanager.set_path(), just ensure prosody.paths.data always contains the correct value (including config)
Matthew Wild <mwild1@gmail.com>
parents:
3999
diff
changeset
|
120 prosody.paths = { source = CFG_SOURCEDIR, config = CFG_CONFIGDIR, |
4167
9c60cc8dc142
prosody, prosodyctl: Use plugin_paths in addition to, not instead of, the default plugin path
Matthew Wild <mwild1@gmail.com>
parents:
4158
diff
changeset
|
121 plugins = CFG_PLUGINDIR or "plugins", data = data_path }; |
4095
6ad7ed619d37
prosodyctl: Instead of calling datamanager.set_path(), just ensure prosody.paths.data always contains the correct value (including config)
Matthew Wild <mwild1@gmail.com>
parents:
3999
diff
changeset
|
122 |
5134
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
123 if prosody.installed then |
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
124 -- Change working directory to data path. |
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
125 require "lfs".chdir(data_path); |
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
126 end |
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
127 |
2587
c37f971f0fe6
prosody, prosodyctl: Re-jiggle load order again, fixes logging config not being obeyed (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents:
2566
diff
changeset
|
128 require "core.loggingmanager" |
c37f971f0fe6
prosody, prosodyctl: Re-jiggle load order again, fixes logging config not being obeyed (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents:
2566
diff
changeset
|
129 |
3904
f93163081b3c
prosody, prosodyctl, util.dependencies: Split checking and logging of dependencies so we can check hard deps before the config and logging is loaded
Matthew Wild <mwild1@gmail.com>
parents:
3777
diff
changeset
|
130 dependencies.log_warnings(); |
2587
c37f971f0fe6
prosody, prosodyctl: Re-jiggle load order again, fixes logging config not being obeyed (thanks darkrain)
Matthew Wild <mwild1@gmail.com>
parents:
2566
diff
changeset
|
131 |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
132 -- Switch away from root and into the prosody user -- |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
133 local switched_user, current_uid; |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
134 |
3481
72d3c8029178
util.pposix: Add pposix.uname(), bump version
Matthew Wild <mwild1@gmail.com>
parents:
3471
diff
changeset
|
135 local want_pposix_version = "0.3.5"; |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
136 local ok, pposix = pcall(require, "util.pposix"); |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
137 |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
138 if ok and pposix then |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
139 if pposix._VERSION ~= want_pposix_version then print(string.format("Unknown version (%s) of binary pposix module, expected %s", tostring(pposix._VERSION), want_pposix_version)); return; end |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
140 current_uid = pposix.getuid(); |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
141 if current_uid == 0 then |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
142 -- We haz root! |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
143 local desired_user = config.get("*", "core", "prosody_user") or "prosody"; |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
144 local desired_group = config.get("*", "core", "prosody_group") or desired_user; |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
145 local ok, err = pposix.setgid(desired_group); |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
146 if ok then |
3471
482275e38224
util.pposix, prosodyctl, mod_posix: Add initgroups() function, and bump module version. prosodyctl inits groups with the groups of prosody_user. (thanks dbb)
Matthew Wild <mwild1@gmail.com>
parents:
3339
diff
changeset
|
147 ok, err = pposix.initgroups(desired_user); |
482275e38224
util.pposix, prosodyctl, mod_posix: Add initgroups() function, and bump module version. prosodyctl inits groups with the groups of prosody_user. (thanks dbb)
Matthew Wild <mwild1@gmail.com>
parents:
3339
diff
changeset
|
148 end |
482275e38224
util.pposix, prosodyctl, mod_posix: Add initgroups() function, and bump module version. prosodyctl inits groups with the groups of prosody_user. (thanks dbb)
Matthew Wild <mwild1@gmail.com>
parents:
3339
diff
changeset
|
149 if ok then |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
150 ok, err = pposix.setuid(desired_user); |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
151 if ok then |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
152 -- Yay! |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
153 switched_user = true; |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
154 end |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
155 end |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
156 if not switched_user then |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
157 -- Boo! |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
158 print("Warning: Couldn't switch to Prosody user/group '"..tostring(desired_user).."'/'"..tostring(desired_group).."': "..tostring(err)); |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
159 end |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
160 end |
2439
511ba389147a
prosodyctl: Set umask to protect data files, bump pposix dep to 0.3.2
Matthew Wild <mwild1@gmail.com>
parents:
2410
diff
changeset
|
161 |
511ba389147a
prosodyctl: Set umask to protect data files, bump pposix dep to 0.3.2
Matthew Wild <mwild1@gmail.com>
parents:
2410
diff
changeset
|
162 -- Set our umask to protect data files |
511ba389147a
prosodyctl: Set umask to protect data files, bump pposix dep to 0.3.2
Matthew Wild <mwild1@gmail.com>
parents:
2410
diff
changeset
|
163 pposix.umask(config.get("*", "core", "umask") or "027"); |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
164 else |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
165 print("Error: Unable to load pposix module. Check that Prosody is installed correctly.") |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
166 print("For more help send the below error to us through http://prosody.im/discuss"); |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
167 print(tostring(pposix)) |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
168 end |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
169 |
3339
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
170 local function test_writeable(filename) |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
171 local f, err = io.open(filename, "a"); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
172 if not f then |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
173 return false, err; |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
174 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
175 f:close(); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
176 return true; |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
177 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
178 |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
179 local unwriteable_files = {}; |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
180 if type(original_logging_config) == "string" and original_logging_config:sub(1,1) ~= "*" then |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
181 local ok, err = test_writeable(original_logging_config); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
182 if not ok then |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
183 table.insert(unwriteable_files, err); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
184 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
185 elseif type(original_logging_config) == "table" then |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
186 for _, rule in ipairs(original_logging_config) do |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
187 if rule.filename then |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
188 local ok, err = test_writeable(rule.filename); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
189 if not ok then |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
190 table.insert(unwriteable_files, err); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
191 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
192 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
193 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
194 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
195 |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
196 if #unwriteable_files > 0 then |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
197 print("One of more of the Prosody log files are not"); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
198 print("writeable, please correct the errors and try"); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
199 print("starting prosodyctl again."); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
200 print(""); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
201 for _, err in ipairs(unwriteable_files) do |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
202 print(err); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
203 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
204 print(""); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
205 os.exit(1); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
206 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
207 |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
208 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
209 local error_messages = setmetatable({ |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
210 ["invalid-username"] = "The given username is invalid in a Jabber ID"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
211 ["invalid-hostname"] = "The given hostname is invalid"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
212 ["no-password"] = "No password was supplied"; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
213 ["no-such-user"] = "The given user does not exist on the server"; |
4827
fefbfd76d2d3
prosodyctl: Show an error if the user doesn't supply a hostname to the certificate commands
Kim Alvefur <zash@zash.se>
parents:
4826
diff
changeset
|
214 ["no-such-host"] = "The given hostname does not exist in the config"; |
1124
055cfdc96afa
prosodyctl: Add message for unable-to-save-data error
Matthew Wild <mwild1@gmail.com>
parents:
1122
diff
changeset
|
215 ["unable-to-save-data"] = "Unable to store, perhaps you don't have permission?"; |
2065
c384ae8ee17a
prosodyctl: Put 'pidfile' in quotes to make more clear that it is the literal name of the option
Matthew Wild <mwild1@gmail.com>
parents:
2020
diff
changeset
|
216 ["no-pidfile"] = "There is no 'pidfile' option in the configuration file, see http://prosody.im/doc/prosodyctl#pidfile for help"; |
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:
3481
diff
changeset
|
217 ["no-posix"] = "The mod_posix module is not enabled in the Prosody config file, see http://prosody.im/doc/prosodyctl for more info"; |
1390
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
218 ["no-such-method"] = "This module has no commands"; |
1460
5882ed6219ff
prosodyctl: Add message for not-running error
Matthew Wild <mwild1@gmail.com>
parents:
1459
diff
changeset
|
219 ["not-running"] = "Prosody is not running"; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
220 }, { __index = function (t,k) return "Error: "..(tostring(k):gsub("%-", " "):gsub("^.", string.upper)); end }); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
221 |
2442
94c676b585c0
prosodyctl: Move definition of prosody singleton to prior to loading datamanager, and add platform
Matthew Wild <mwild1@gmail.com>
parents:
2439
diff
changeset
|
222 hosts = prosody.hosts; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
223 |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
224 local function make_host(hostname) |
3630
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
225 return { |
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
226 type = "local", |
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
227 events = prosody.events, |
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
228 users = require "core.usermanager".new_null_provider(hostname) |
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
229 }; |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
230 end |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
231 |
2020
24f54340a670
prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents:
1580
diff
changeset
|
232 for hostname, config in pairs(config.getconfig()) do |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
233 hosts[hostname] = make_host(hostname); |
2020
24f54340a670
prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents:
1580
diff
changeset
|
234 end |
24f54340a670
prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents:
1580
diff
changeset
|
235 |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4881
diff
changeset
|
236 local modulemanager = require "core.modulemanager" |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
237 |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4881
diff
changeset
|
238 local prosodyctl = require "util.prosodyctl" |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
239 require "socket" |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
240 ----------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
241 |
4881
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
242 -- FIXME: Duplicate code waiting for util.startup |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
243 function read_version() |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
244 -- Try to determine version |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
245 local version_file = io.open((CFG_SOURCEDIR or ".").."/prosody.version"); |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
246 if version_file then |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
247 prosody.version = version_file:read("*a"):gsub("%s*$", ""); |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
248 version_file:close(); |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
249 if #prosody.version == 12 and prosody.version:match("^[a-f0-9]+$") then |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
250 prosody.version = "hg:"..prosody.version; |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
251 end |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
252 else |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
253 prosody.version = "unknown"; |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
254 end |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
255 end |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
256 |
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:
4095
diff
changeset
|
257 local show_message, show_warning = prosodyctl.show_message, prosodyctl.show_warning; |
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:
4095
diff
changeset
|
258 local show_usage = prosodyctl.show_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:
4095
diff
changeset
|
259 local getchar, getpass = prosodyctl.getchar, prosodyctl.getpass; |
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:
4095
diff
changeset
|
260 local show_yesno = prosodyctl.show_yesno; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
261 local show_prompt = prosodyctl.show_prompt; |
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:
4095
diff
changeset
|
262 local read_password = prosodyctl.read_password; |
1459
545208bc0e84
prosodyctl: Use prosodyctl_timeout option if it exists in the config
Matthew Wild <mwild1@gmail.com>
parents:
1458
diff
changeset
|
263 |
545208bc0e84
prosodyctl: Use prosodyctl_timeout option if it exists in the config
Matthew Wild <mwild1@gmail.com>
parents:
1458
diff
changeset
|
264 local prosodyctl_timeout = (config.get("*", "core", "prosodyctl_timeout") or 5) * 2; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
265 ----------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
266 local commands = {}; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
267 local command = arg[1]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
268 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
269 function commands.adduser(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
270 if not arg[1] or arg[1] == "--help" then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
271 show_usage([[adduser JID]], [[Create the specified user account in Prosody]]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
272 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
273 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
274 local user, host = arg[1]:match("([^@]+)@(.+)"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
275 if not user and host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
276 show_message [[Failed to understand JID, please supply the JID you want to create]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
277 show_usage [[adduser user@host]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
278 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
279 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
280 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
281 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
282 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
283 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
284 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
285 |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
286 if not hosts[host] then |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
287 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
288 show_warning("The user will not be able to log in until this is changed."); |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
289 hosts[host] = make_host(host); |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
290 end |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
291 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
292 if prosodyctl.user_exists{ user = user, host = host } then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
293 show_message [[That user already exists]]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
294 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
295 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
296 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
297 local password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
298 if not password then return 1; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
299 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
300 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
301 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
302 if ok then return 0; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
303 |
3777
5ecbcef42ffb
mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents:
3773
diff
changeset
|
304 show_message(msg) |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
305 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
306 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
307 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
308 function commands.passwd(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
309 if not arg[1] or arg[1] == "--help" then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
310 show_usage([[passwd JID]], [[Set the password for the specified user account in Prosody]]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
311 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
312 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
313 local user, host = arg[1]:match("([^@]+)@(.+)"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
314 if not user and host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
315 show_message [[Failed to understand JID, please supply the JID you want to set the password for]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
316 show_usage [[passwd user@host]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
317 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
318 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
319 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
320 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
321 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
322 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
323 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
324 |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
325 if not hosts[host] then |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
326 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
327 show_warning("The user will not be able to log in until this is changed."); |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
328 hosts[host] = make_host(host); |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
329 end |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
330 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
331 if not prosodyctl.user_exists { user = user, host = host } then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
332 show_message [[That user does not exist, use prosodyctl adduser to create a new user]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
333 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
334 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
335 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
336 local password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
337 if not password then return 1; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
338 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
339 local ok, msg = prosodyctl.passwd { user = user, host = host, password = password }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
340 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
341 if ok then return 0; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
342 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
343 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
344 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
345 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
346 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
347 function commands.deluser(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
348 if not arg[1] or arg[1] == "--help" then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
349 show_usage([[deluser JID]], [[Permanently remove the specified user account from Prosody]]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
350 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
351 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
352 local user, host = arg[1]:match("([^@]+)@(.+)"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
353 if not user and host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
354 show_message [[Failed to understand JID, please supply the JID you want to set the password for]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
355 show_usage [[passwd user@host]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
356 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
357 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
358 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
359 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
360 show_message [[Please specify a JID, including a host. e.g. alice@example.com]]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
361 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
362 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
363 |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
364 if not hosts[host] then |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
365 show_warning("The host '%s' is not listed in the configuration file (or is not enabled).", host) |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
366 show_warning("The user will not be able to log in until this is changed."); |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
367 hosts[host] = make_host(host); |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
368 end |
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
369 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
370 if not prosodyctl.user_exists { user = user, host = host } then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
371 show_message [[That user does not exist on this server]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
372 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
373 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
374 |
5101
a94c43cad081
prosodyctl: Use util.prosodyctl.deluser
Kim Alvefur <zash@zash.se>
parents:
5024
diff
changeset
|
375 local ok, msg = prosodyctl.deluser { user = user, host = host }; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
376 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
377 if ok then return 0; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
378 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
379 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
380 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
381 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
382 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
383 function commands.start(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
384 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
385 show_usage([[start]], [[Start Prosody]]); |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
386 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
387 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
388 local ok, ret = prosodyctl.isrunning(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
389 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
390 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
391 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
392 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
393 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
394 if ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
395 local ok, ret = prosodyctl.getpid(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
396 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
397 show_message("Couldn't get running Prosody's PID"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
398 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
399 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
400 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
401 show_message("Prosody is already running with PID %s", ret or "(unknown)"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
402 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
403 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
404 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
405 local ok, ret = prosodyctl.start(); |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
406 if ok then |
2511
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
407 if config.get("*", "core", "daemonize") ~= false then |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
408 local i=1; |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
409 while true do |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
410 local ok, running = prosodyctl.isrunning(); |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
411 if ok and running then |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
412 break; |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
413 elseif i == 5 then |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
414 show_message("Still waiting..."); |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
415 elseif i >= prosodyctl_timeout then |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
416 show_message("Prosody is still not running. Please give it some time or check your log files for errors."); |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
417 return 2; |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
418 end |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
419 socket.sleep(0.5); |
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
420 i = i + 1; |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
421 end |
2511
a81c710b1708
prosodyctl: Don't display message about failing to start Prosody is daemonizing is disabled (if daemonizing is disabled then Prosody is stopped by the time control returns to prosodyctl, which then can't see Prosody running)
Matthew Wild <mwild1@gmail.com>
parents:
2510
diff
changeset
|
422 show_message("Started"); |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
423 end |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
424 return 0; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
425 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
426 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
427 show_message("Failed to start Prosody"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
428 show_message(error_messages[ret]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
429 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
430 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
431 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
432 function commands.status(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
433 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
434 show_usage([[status]], [[Reports the running status of Prosody]]); |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
435 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
436 end |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
437 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
438 local ok, ret = prosodyctl.isrunning(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
439 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
440 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
441 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
442 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
443 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
444 if ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
445 local ok, ret = prosodyctl.getpid(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
446 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
447 show_message("Couldn't get running Prosody's PID"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
448 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
449 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
450 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
451 show_message("Prosody is running with PID %s", ret or "(unknown)"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
452 return 0; |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
453 else |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
454 show_message("Prosody is not running"); |
1115
8a7bc1a5eae6
prosodyctl: status: Show warning if we can't find a running Prosody, and we didn't switch user
Matthew Wild <mwild1@gmail.com>
parents:
1114
diff
changeset
|
455 if not switched_user and current_uid ~= 0 then |
1122
07b2b5942957
prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents:
1120
diff
changeset
|
456 print("\nNote:") |
07b2b5942957
prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents:
1120
diff
changeset
|
457 print(" You will also see this if prosodyctl is not running under"); |
07b2b5942957
prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents:
1120
diff
changeset
|
458 print(" the same user account as Prosody. Try running as root (e.g. "); |
07b2b5942957
prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents:
1120
diff
changeset
|
459 print(" with 'sudo' in front) to gain access to Prosody's real status."); |
1115
8a7bc1a5eae6
prosodyctl: status: Show warning if we can't find a running Prosody, and we didn't switch user
Matthew Wild <mwild1@gmail.com>
parents:
1114
diff
changeset
|
460 end |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
461 return 2 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
462 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
463 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
464 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
465 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
466 function commands.stop(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
467 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
468 show_usage([[stop]], [[Stop a running Prosody server]]); |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
469 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
470 end |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
471 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
472 if not prosodyctl.isrunning() then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
473 show_message("Prosody is not running"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
474 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
475 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
476 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
477 local ok, ret = prosodyctl.stop(); |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
478 if ok then |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
479 local i=1; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
480 while true do |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
481 local ok, running = prosodyctl.isrunning(); |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
482 if ok and not running then |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
483 break; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
484 elseif i == 5 then |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
485 show_message("Still waiting..."); |
1459
545208bc0e84
prosodyctl: Use prosodyctl_timeout option if it exists in the config
Matthew Wild <mwild1@gmail.com>
parents:
1458
diff
changeset
|
486 elseif i >= prosodyctl_timeout then |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
487 show_message("Prosody is still running. Please give it some time or check your log files for errors."); |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
488 return 2; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
489 end |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
490 socket.sleep(0.5); |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
491 i = i + 1; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
492 end |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
493 show_message("Stopped"); |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
494 return 0; |
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
495 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
496 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
497 show_message(error_messages[ret]); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
498 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
499 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
500 |
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
501 function commands.restart(arg) |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
502 if arg[1] == "--help" then |
2705
8a5af6f14c07
prosodyctl: Fix 'restart' command to not report itself as the 'stop' command (thanks albert!)
Matthew Wild <mwild1@gmail.com>
parents:
2696
diff
changeset
|
503 show_usage([[restart]], [[Restart a running Prosody server]]); |
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
504 return 1; |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
505 end |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
506 |
3724
c12ebbd4ab61
prosodyctl: Make the 'restart' command start Prosody even if it wasn't already running
Matthew Wild <mwild1@gmail.com>
parents:
3630
diff
changeset
|
507 commands.stop(arg); |
c12ebbd4ab61
prosodyctl: Make the 'restart' command start Prosody even if it wasn't already running
Matthew Wild <mwild1@gmail.com>
parents:
3630
diff
changeset
|
508 return commands.start(arg); |
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
509 end |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
510 |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
511 function commands.about(arg) |
4881
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
512 read_version(); |
4331
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
513 if arg[1] == "--help" then |
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
514 show_usage([[about]], [[Show information about this Prosody installation]]); |
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
515 return 1; |
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
516 end |
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
517 |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4881
diff
changeset
|
518 local array = require "util.array"; |
4815
04e6115e060b
prosodyctl: Fix import of util.iterators
Kim Alvefur <zash@zash.se>
parents:
4487
diff
changeset
|
519 local keys = require "util.iterators".keys; |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
520 |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
521 print("Prosody "..(prosody.version or "(unknown version)")); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
522 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
523 print("# Prosody directories"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
524 print("Data directory: ", CFG_DATADIR or "./"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
525 print("Plugin directory:", CFG_PLUGINDIR or "./"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
526 print("Config directory:", CFG_CONFIGDIR or "./"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
527 print("Source directory:", CFG_SOURCEDIR or "./"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
528 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
529 print("# Lua environment"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
530 print("Lua version: ", _G._VERSION); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
531 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
532 print("Lua module search paths:"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
533 for path in package.path:gmatch("[^;]+") do |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
534 print(" "..path); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
535 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
536 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
537 print("Lua C module search paths:"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
538 for path in package.cpath:gmatch("[^;]+") do |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
539 print(" "..path); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
540 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
541 print(""); |
4333
040193dead77
prosodyctl: Add info about the presence of LuaRocks to 'about' command
Matthew Wild <mwild1@gmail.com>
parents:
4331
diff
changeset
|
542 local luarocks_status = (pcall(require, "luarocks.loader") and "Installed ("..(luarocks.cfg.program_version or "2.x+")..")") |
4334
cd1b73582711
prosodyctl: Remove typo'd '+' after LuaRocks 1.x version (thanks spoobie)
Matthew Wild <mwild1@gmail.com>
parents:
4333
diff
changeset
|
543 or (pcall(require, "luarocks.require") and "Installed (1.x)") |
4333
040193dead77
prosodyctl: Add info about the presence of LuaRocks to 'about' command
Matthew Wild <mwild1@gmail.com>
parents:
4331
diff
changeset
|
544 or "Not installed"; |
040193dead77
prosodyctl: Add info about the presence of LuaRocks to 'about' command
Matthew Wild <mwild1@gmail.com>
parents:
4331
diff
changeset
|
545 print("LuaRocks: ", luarocks_status); |
040193dead77
prosodyctl: Add info about the presence of LuaRocks to 'about' command
Matthew Wild <mwild1@gmail.com>
parents:
4331
diff
changeset
|
546 print(""); |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
547 print("# Lua module versions"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
548 local module_versions, longest_name = {}, 8; |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
549 for name, module in pairs(package.loaded) do |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
550 if type(module) == "table" and rawget(module, "_VERSION") |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
551 and name ~= "_G" and not name:match("%.") then |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
552 if #name > longest_name then |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
553 longest_name = #name; |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
554 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
555 module_versions[name] = module._VERSION; |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
556 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
557 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
558 local sorted_keys = array.collect(keys(module_versions)):sort(); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
559 for _, name in ipairs(array.collect(keys(module_versions)):sort()) do |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
560 print(name..":"..string.rep(" ", longest_name-#name), module_versions[name]); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
561 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
562 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
563 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
564 |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
565 function commands.reload(arg) |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
566 if arg[1] == "--help" then |
4476
53ce21286b8c
prosodyctl: Adjust description of 'reload' command (thanks crocket)
Matthew Wild <mwild1@gmail.com>
parents:
4336
diff
changeset
|
567 show_usage([[reload]], [[Reload Prosody's configuration and re-open log files]]); |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
568 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
569 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
570 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
571 if not prosodyctl.isrunning() then |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
572 show_message("Prosody is not running"); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
573 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
574 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
575 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
576 local ok, ret = prosodyctl.reload(); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
577 if ok then |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
578 |
4336
abcbcb15205c
prosodyctl: Update message on reload success
Matthew Wild <mwild1@gmail.com>
parents:
4335
diff
changeset
|
579 show_message("Prosody log files re-opened and config file reloaded. You may need to reload modules for some changes to take effect."); |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
580 return 0; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
581 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
582 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
583 show_message(error_messages[ret]); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
584 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
585 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
586 -- ejabberdctl compatibility |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
587 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
588 function commands.register(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
589 local user, host, password = unpack(arg); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
590 if (not (user and host)) or arg[1] == "--help" then |
1102
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
591 if user ~= "--help" then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
592 if not user then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
593 show_message [[No username specified]] |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
594 elseif not host then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
595 show_message [[Please specify which host you want to register the user on]]; |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
596 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
597 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
598 show_usage("register USER HOST [PASSWORD]", "Register a user on the server, with the given password"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
599 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
600 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
601 if not password then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
602 password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
603 if not password then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
604 show_message [[Unable to register user with no password]]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
605 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
606 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
607 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
608 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
609 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
610 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
611 if ok then return 0; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
612 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
613 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
614 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
615 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
616 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
617 function commands.unregister(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
618 local user, host = unpack(arg); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
619 if (not (user and host)) or arg[1] == "--help" then |
1102
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
620 if user ~= "--help" then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
621 if not user then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
622 show_message [[No username specified]] |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
623 elseif not host then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
624 show_message [[Please specify which host you want to unregister the user from]]; |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
625 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
626 end |
1102
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
627 show_usage("unregister USER HOST [PASSWORD]", "Permanently remove a user account from the server"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
628 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
629 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
630 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
631 local ok, msg = prosodyctl.deluser { user = user, host = host }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
632 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
633 if ok then return 0; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
634 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
635 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
636 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
637 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
638 |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
639 local openssl = require "util.openssl"; |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
640 local lfs = require "lfs"; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
641 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
642 local cert_commands = {}; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
643 |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
644 local function ask_overwrite(filename) |
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
645 return lfs.attributes(filename) and not show_yesno("Overwrite "..filename .. "?"); |
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
646 end |
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
647 |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
648 function cert_commands.config(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
649 if #arg >= 1 and arg[1] ~= "--help" then |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
650 local conf_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".cnf"; |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
651 if ask_overwrite(conf_filename) then |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
652 return nil, conf_filename; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
653 end |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
654 local conf = openssl.config.new(); |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
655 conf:from_prosody(hosts, config, arg); |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
656 for k, v in pairs(conf.distinguished_name) do |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
657 local nv; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
658 if k == "commonName" then |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
659 v = arg[1] |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
660 elseif k == "emailAddress" then |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
661 v = "xmpp@" .. arg[1]; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
662 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
663 nv = show_prompt(("%s (%s):"):format(k, nv or v)); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
664 nv = (not nv or nv == "") and v or nv; |
4878
80ab7c50608d
prosodyctl: Fix for generating certs with UTF-8
Kim Alvefur <zash@zash.se>
parents:
4872
diff
changeset
|
665 if nv:find"[\192-\252][\128-\191]+" then |
80ab7c50608d
prosodyctl: Fix for generating certs with UTF-8
Kim Alvefur <zash@zash.se>
parents:
4872
diff
changeset
|
666 conf.req.string_mask = "utf8only" |
80ab7c50608d
prosodyctl: Fix for generating certs with UTF-8
Kim Alvefur <zash@zash.se>
parents:
4872
diff
changeset
|
667 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
668 conf.distinguished_name[k] = nv ~= "." and nv or nil; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
669 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
670 local conf_file = io.open(conf_filename, "w"); |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
671 conf_file:write(conf:serialize()); |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
672 conf_file:close(); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
673 print(""); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
674 show_message("Config written to " .. conf_filename); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
675 return nil, conf_filename; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
676 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
677 show_usage("cert config HOSTNAME [HOSTNAME+]", "Builds a certificate config file covering the supplied hostname(s)") |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
678 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
679 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
680 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
681 function cert_commands.key(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
682 if #arg >= 1 and arg[1] ~= "--help" then |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
683 local key_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".key"; |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
684 if ask_overwrite(key_filename) then |
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
685 return nil, key_filename; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
686 end |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
687 os.remove(key_filename); -- We chmod this file to not have write permissions |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
688 local key_size = tonumber(arg[2] or show_prompt("Choose key size (2048):") or 2048); |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
689 if openssl.genrsa{out=key_filename, key_size} then |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
690 os.execute(("chmod 400 '%s'"):format(key_filename)); |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
691 show_message("Key written to ".. key_filename); |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
692 return nil, key_filename; |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
693 end |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
694 show_message("There was a problem, see OpenSSL output"); |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
695 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
696 show_usage("cert key HOSTNAME <bits>", "Generates a RSA key named HOSTNAME.key\n " |
4935 | 697 .."Prompts for a key size if none given") |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
698 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
699 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
700 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
701 function cert_commands.request(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
702 if #arg >= 1 and arg[1] ~= "--help" then |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
703 local req_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".req"; |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
704 if ask_overwrite(req_filename) then |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
705 return nil, req_filename; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
706 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
707 local _, key_filename = cert_commands.key({arg[1]}); |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
708 local _, conf_filename = cert_commands.config(arg); |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
709 if openssl.req{new=true, key=key_filename, utf8=true, config=conf_filename, out=req_filename} then |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
710 show_message("Certificate request written to ".. req_filename); |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
711 else |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
712 show_message("There was a problem, see OpenSSL output"); |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
713 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
714 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
715 show_usage("cert request HOSTNAME [HOSTNAME+]", "Generates a certificate request for the supplied hostname(s)") |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
716 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
717 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
718 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
719 function cert_commands.generate(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
720 if #arg >= 1 and arg[1] ~= "--help" then |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
721 local cert_filename = (CFG_DATADIR or ".") .. "/" .. arg[1] .. ".cert"; |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
722 if ask_overwrite(cert_filename) then |
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
723 return nil, conf_filename; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
724 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
725 local _, key_filename = cert_commands.key({arg[1]}); |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
726 local _, conf_filename = cert_commands.config(arg); |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
727 local ret; |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
728 if key_filename and conf_filename and cert_filename |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
729 and openssl.req{new=true, x509=true, nodes=true, key=key_filename, |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
730 days=365, sha1=true, utf8=true, config=conf_filename, out=cert_filename} then |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
731 show_message("Certificate written to ".. cert_filename); |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
732 else |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
733 show_message("There was a problem, see OpenSSL output"); |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
734 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
735 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
736 show_usage("cert generate HOSTNAME [HOSTNAME+]", "Generates a self-signed certificate for the current hostname(s)") |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
737 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
738 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
739 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
740 function commands.cert(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
741 if #arg >= 1 and arg[1] ~= "--help" then |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
742 local subcmd = table.remove(arg, 1); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
743 if type(cert_commands[subcmd]) == "function" then |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
744 if not arg[1] then |
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
745 show_message"You need to supply at least one hostname" |
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
746 arg = { "--help" }; |
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
747 end |
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
748 if arg[1] ~= "--help" and not hosts[arg[1]] then |
4827
fefbfd76d2d3
prosodyctl: Show an error if the user doesn't supply a hostname to the certificate commands
Kim Alvefur <zash@zash.se>
parents:
4826
diff
changeset
|
749 show_message(error_messages["no-such-host"]); |
fefbfd76d2d3
prosodyctl: Show an error if the user doesn't supply a hostname to the certificate commands
Kim Alvefur <zash@zash.se>
parents:
4826
diff
changeset
|
750 return |
fefbfd76d2d3
prosodyctl: Show an error if the user doesn't supply a hostname to the certificate commands
Kim Alvefur <zash@zash.se>
parents:
4826
diff
changeset
|
751 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
752 return cert_commands[subcmd](arg); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
753 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
754 end |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
755 show_usage("cert config|request|generate|key", "Helpers for generating X.509 certificates and keys.") |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
756 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
757 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
758 --------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
759 |
1499
51e3e22b5316
prosodyctl: Fix traceback when issued with no parameters
Matthew Wild <mwild1@gmail.com>
parents:
1460
diff
changeset
|
760 if command and command:match("^mod_") then -- Is a command in a module |
1390
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
761 local module_name = command:match("^mod_(.+)"); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
762 local ret, err = modulemanager.load("*", module_name); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
763 if not ret then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
764 show_message("Failed to load module '"..module_name.."': "..err); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
765 os.exit(1); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
766 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
767 |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
768 table.remove(arg, 1); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
769 |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
770 local module = modulemanager.get_module("*", module_name); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
771 if not module then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
772 show_message("Failed to load module '"..module_name.."': Unknown error"); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
773 os.exit(1); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
774 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
775 |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
776 if not modulemanager.module_has_method(module, "command") then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
777 show_message("Fail: mod_"..module_name.." does not support any commands"); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
778 os.exit(1); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
779 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
780 |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
781 local ok, ret = modulemanager.call_module_method(module, "command", arg); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
782 if ok then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
783 if type(ret) == "number" then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
784 os.exit(ret); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
785 elseif type(ret) == "string" then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
786 show_message(ret); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
787 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
788 os.exit(0); -- :) |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
789 else |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
790 show_message("Failed to execute command: "..error_messages[ret]); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
791 os.exit(1); -- :( |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
792 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
793 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
794 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
795 if not commands[command] then -- Show help for all commands |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
796 function show_usage(usage, desc) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
797 print(" "..usage); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
798 print(" "..desc); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
799 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
800 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
801 print("prosodyctl - Manage a Prosody server"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
802 print(""); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
803 print("Usage: "..arg[0].." COMMAND [OPTIONS]"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
804 print(""); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
805 print("Where COMMAND may be one of:\n"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
806 |
2706
c2dde8bda3fe
prosodyctl: Fix addplugin to support --help, and hide from the help listing (for now)
Matthew Wild <mwild1@gmail.com>
parents:
2705
diff
changeset
|
807 local hidden_commands = require "util.set".new{ "register", "unregister", "addplugin" }; |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
808 local commands_order = { "adduser", "passwd", "deluser", "start", "stop", "restart", "reload", "about" }; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
809 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
810 local done = {}; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
811 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
812 for _, command_name in ipairs(commands_order) do |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
813 local command = commands[command_name]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
814 if command then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
815 command{ "--help" }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
816 print"" |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
817 done[command_name] = true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
818 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
819 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
820 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
821 for command_name, command in pairs(commands) do |
1102
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
822 if not done[command_name] and not hidden_commands:contains(command_name) then |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
823 command{ "--help" }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
824 print"" |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
825 done[command_name] = true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
826 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
827 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
828 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
829 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
830 os.exit(0); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
831 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
832 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
833 os.exit(commands[command]({ select(2, unpack(arg)) })); |