Software /
code /
prosody
Annotate
prosodyctl @ 8277:57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 27 Sep 2017 15:37:10 +0200 |
parent | 8276:5ebad58b2548 |
child | 8285:433b2a41351f |
child | 8419:57610304e30d |
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 |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
5 -- |
1087
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 |
7297
b34a42a10c9f
prosody, prosodyctl: Allow setting CFG_* variables via Lua interpreter before loading Prosody. Fixes #308.
Matthew Wild <mwild1@gmail.com>
parents:
7267
diff
changeset
|
14 CFG_SOURCEDIR=CFG_SOURCEDIR or os.getenv("PROSODY_SRCDIR"); |
b34a42a10c9f
prosody, prosodyctl: Allow setting CFG_* variables via Lua interpreter before loading Prosody. Fixes #308.
Matthew Wild <mwild1@gmail.com>
parents:
7267
diff
changeset
|
15 CFG_CONFIGDIR=CFG_CONFIGDIR or os.getenv("PROSODY_CFGDIR"); |
b34a42a10c9f
prosody, prosodyctl: Allow setting CFG_* variables via Lua interpreter before loading Prosody. Fixes #308.
Matthew Wild <mwild1@gmail.com>
parents:
7267
diff
changeset
|
16 CFG_PLUGINDIR=CFG_PLUGINDIR or os.getenv("PROSODY_PLUGINDIR"); |
b34a42a10c9f
prosody, prosodyctl: Allow setting CFG_* variables via Lua interpreter before loading Prosody. Fixes #308.
Matthew Wild <mwild1@gmail.com>
parents:
7267
diff
changeset
|
17 CFG_DATADIR=CFG_DATADIR or os.getenv("PROSODY_DATADIR"); |
1087
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); |
8104 | 23 return ((path_sep == "/" and path:sub(1,1) ~= "/") |
24 or (path_sep == "\\" and (path:sub(1,1) ~= "/" and path:sub(2,3) ~= ":\\"))) | |
3999
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; |
5438
5032b3b5b556
prosodyctl: Define prosody.core_post_stanza as an empty function
Matthew Wild <mwild1@gmail.com>
parents:
5384
diff
changeset
|
54 core_post_stanza = function () end; -- TODO: mod_router! |
3013
518e3f6f9946
prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents:
2706
diff
changeset
|
55 }; |
3998
009d1ad84b49
prosody, prosodyctl: Create prosody object as a local before exporting as a global
Matthew Wild <mwild1@gmail.com>
parents:
3904
diff
changeset
|
56 _G.prosody = prosody; |
3013
518e3f6f9946
prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents:
2706
diff
changeset
|
57 |
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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
63 config = require "core.configmanager" |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
64 |
5296
78b7a4ad2f32
prosodyctl, prosody: Pass the selected config file from prosodyctl to prosody
Kim Alvefur <zash@zash.se>
parents:
5295
diff
changeset
|
65 local ENV_CONFIG; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
66 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
|
67 local filenames = {}; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
68 |
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
|
69 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
|
70 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
|
71 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
|
72 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
|
73 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
|
74 end |
5295
eef393a37e38
prosodyctl: Pop arg items after use. Fixes #306
Kim Alvefur <zash@zash.se>
parents:
5293
diff
changeset
|
75 table.remove(arg, 1); table.remove(arg, 1); |
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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 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
|
81 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
|
82 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
|
83 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
|
84 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
|
85 file:close(); |
5296
78b7a4ad2f32
prosodyctl, prosody: Pass the selected config file from prosodyctl to prosody
Kim Alvefur <zash@zash.se>
parents:
5295
diff
changeset
|
86 ENV_CONFIG = filename; |
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
|
87 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
|
88 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
|
89 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
|
90 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
|
91 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
|
92 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
93 print("\n"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
94 print("**************************"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
95 if level == "parser" then |
8276
5ebad58b2548
prosody, prosodyctl: Print the actual config file name used when a problem loading it was encountered (see #990)
Kim Alvefur <zash@zash.se>
parents:
8274
diff
changeset
|
96 print("A problem occured while reading the config file "..filename); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
97 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
|
98 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
|
99 print(""); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
100 elseif level == "file" then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
101 print("Prosody was unable to find the configuration file."); |
8276
5ebad58b2548
prosody, prosodyctl: Print the actual config file name used when a problem loading it was encountered (see #990)
Kim Alvefur <zash@zash.se>
parents:
8274
diff
changeset
|
102 print("We looked for: "..filename); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
103 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
|
104 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
|
105 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
106 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
|
107 print("Good luck!"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
108 print("**************************"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
109 print(""); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
110 os.exit(1); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
111 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
112 end |
5384
24f4aed5824f
prosody, prosodyctl: Remove last trace of "core" \o/
Kim Alvefur <zash@zash.se>
parents:
5296
diff
changeset
|
113 local original_logging_config = config.get("*", "log"); |
24f4aed5824f
prosody, prosodyctl: Remove last trace of "core" \o/
Kim Alvefur <zash@zash.se>
parents:
5296
diff
changeset
|
114 config.set("*", "log", { { levels = { min="info" }, to = "console" } }); |
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
|
115 |
5384
24f4aed5824f
prosody, prosodyctl: Remove last trace of "core" \o/
Kim Alvefur <zash@zash.se>
parents:
5296
diff
changeset
|
116 local data_path = config.get("*", "data_path") or CFG_DATADIR or "data"; |
24f4aed5824f
prosody, prosodyctl: Remove last trace of "core" \o/
Kim Alvefur <zash@zash.se>
parents:
5296
diff
changeset
|
117 local custom_plugin_paths = config.get("*", "plugin_paths"); |
4158
14581c3f33bd
prosodyctl: Support for plugin_paths config option
Matthew Wild <mwild1@gmail.com>
parents:
4142
diff
changeset
|
118 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
|
119 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
|
120 -- 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
|
121 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
|
122 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
123 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
|
124 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
|
125 |
5134
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
126 if prosody.installed then |
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
127 -- Change working directory to data path. |
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
128 require "lfs".chdir(data_path); |
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
129 end |
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
130 |
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 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
|
132 |
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
|
133 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
|
134 |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
135 -- 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
|
136 local switched_user, current_uid; |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
137 |
8012 | 138 local want_pposix_version = "0.4.0"; |
8099
04eaaeb89a05
prosodyctl: Rename variable for soft-require success to improve readability
Kim Alvefur <zash@zash.se>
parents:
8098
diff
changeset
|
139 local have_pposix, pposix = pcall(require, "util.pposix"); |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
140 |
8099
04eaaeb89a05
prosodyctl: Rename variable for soft-require success to improve readability
Kim Alvefur <zash@zash.se>
parents:
8098
diff
changeset
|
141 if have_pposix and pposix then |
8110
9aeb1c631f62
prosodyctl: Split long line [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8109
diff
changeset
|
142 if pposix._VERSION ~= want_pposix_version then |
9aeb1c631f62
prosodyctl: Split long line [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8109
diff
changeset
|
143 print(string.format("Unknown version (%s) of binary pposix module, expected %s", |
9aeb1c631f62
prosodyctl: Split long line [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8109
diff
changeset
|
144 tostring(pposix._VERSION), want_pposix_version)); return; |
9aeb1c631f62
prosodyctl: Split long line [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8109
diff
changeset
|
145 end |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
146 current_uid = pposix.getuid(); |
8098
ee1c81450345
prosodyctl: Remove --root from arg array
Kim Alvefur <zash@zash.se>
parents:
8096
diff
changeset
|
147 local arg_root = arg[1] == "--root"; |
ee1c81450345
prosodyctl: Remove --root from arg array
Kim Alvefur <zash@zash.se>
parents:
8096
diff
changeset
|
148 if arg_root then table.remove(arg, 1); end |
ee1c81450345
prosodyctl: Remove --root from arg array
Kim Alvefur <zash@zash.se>
parents:
8096
diff
changeset
|
149 if current_uid == 0 and config.get("*", "run_as_root") ~= true and not arg_root then |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
150 -- We haz root! |
5384
24f4aed5824f
prosody, prosodyctl: Remove last trace of "core" \o/
Kim Alvefur <zash@zash.se>
parents:
5296
diff
changeset
|
151 local desired_user = config.get("*", "prosody_user") or "prosody"; |
24f4aed5824f
prosody, prosodyctl: Remove last trace of "core" \o/
Kim Alvefur <zash@zash.se>
parents:
5296
diff
changeset
|
152 local desired_group = config.get("*", "prosody_group") or desired_user; |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
153 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
|
154 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
|
155 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
|
156 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
|
157 if ok then |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
158 ok, err = pposix.setuid(desired_user); |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
159 if ok then |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
160 -- Yay! |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
161 switched_user = true; |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
162 end |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
163 end |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
164 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
|
165 -- Boo! |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
166 print("Warning: Couldn't switch to Prosody user/group '"..tostring(desired_user).."'/'"..tostring(desired_group).."': "..tostring(err)); |
8277
57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
Kim Alvefur <zash@zash.se>
parents:
8276
diff
changeset
|
167 else |
57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
Kim Alvefur <zash@zash.se>
parents:
8276
diff
changeset
|
168 -- Make sure the Prosody user can read the config |
57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
Kim Alvefur <zash@zash.se>
parents:
8276
diff
changeset
|
169 local conf, err, errno = io.open(ENV_CONFIG); |
57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
Kim Alvefur <zash@zash.se>
parents:
8276
diff
changeset
|
170 if conf then |
57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
Kim Alvefur <zash@zash.se>
parents:
8276
diff
changeset
|
171 conf:close(); |
57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
Kim Alvefur <zash@zash.se>
parents:
8276
diff
changeset
|
172 else |
57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
Kim Alvefur <zash@zash.se>
parents:
8276
diff
changeset
|
173 print("The config file is not readable by the '"..desired_user.."' user."); |
57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
Kim Alvefur <zash@zash.se>
parents:
8276
diff
changeset
|
174 print("Prosody will not be able to read it."); |
57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
Kim Alvefur <zash@zash.se>
parents:
8276
diff
changeset
|
175 print("Error was "..err); |
57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
Kim Alvefur <zash@zash.se>
parents:
8276
diff
changeset
|
176 os.exit(1); |
57c5dd08ff0a
prosodyctl: Abort and warn if the config can't be opened after dropping root privileges (fixes #990)
Kim Alvefur <zash@zash.se>
parents:
8276
diff
changeset
|
177 end |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
178 end |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
179 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
180 |
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
|
181 -- Set our umask to protect data files |
5384
24f4aed5824f
prosody, prosodyctl: Remove last trace of "core" \o/
Kim Alvefur <zash@zash.se>
parents:
5296
diff
changeset
|
182 pposix.umask(config.get("*", "umask") or "027"); |
5149
b3e9b3576056
prosodyctl: Set $HOME to data path. Fixes issue with openssl and random state (Thanks Florob)
Kim Alvefur <zash@zash.se>
parents:
5142
diff
changeset
|
183 pposix.setenv("HOME", data_path); |
5296
78b7a4ad2f32
prosodyctl, prosody: Pass the selected config file from prosodyctl to prosody
Kim Alvefur <zash@zash.se>
parents:
5295
diff
changeset
|
184 pposix.setenv("PROSODY_CONFIG", ENV_CONFIG); |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
185 else |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
186 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
|
187 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
|
188 print(tostring(pposix)) |
5150
81b49bb0ecc7
prosodyctl: Abort if unable to load util.pposix
Kim Alvefur <zash@zash.se>
parents:
5149
diff
changeset
|
189 os.exit(1); |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
190 end |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
191 |
3339
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
192 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
|
193 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
|
194 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
|
195 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
|
196 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
197 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
|
198 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
|
199 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
200 |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
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 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
|
208 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
|
209 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
|
210 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
|
211 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
|
212 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
|
213 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
214 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
215 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
216 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
217 |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
218 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
|
219 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
|
220 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
|
221 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
|
222 print(""); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
223 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
|
224 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
|
225 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
226 print(""); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
227 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
|
228 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
229 |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
230 |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
231 local error_messages = setmetatable({ |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
232 ["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
|
233 ["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
|
234 ["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
|
235 ["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
|
236 ["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
|
237 ["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
|
238 ["no-pidfile"] = "There is no 'pidfile' option in the configuration file, see http://prosody.im/doc/prosodyctl#pidfile for help"; |
6356
fb1535328ac7
prosodyctl: Verify that 'pidfile' is a string, show friendly error otherwise
Kim Alvefur <zash@zash.se>
parents:
6325
diff
changeset
|
239 ["invalid-pidfile"] = "The 'pidfile' option in the configuration file is not a string, 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
|
240 ["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
|
241 ["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
|
242 ["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
|
243 }, { __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
|
244 |
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
|
245 hosts = prosody.hosts; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
246 |
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
|
247 local function make_host(hostname) |
3630
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
248 return { |
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
249 type = "local", |
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
250 events = prosody.events, |
5142
3221746f4769
prosodyctl: Make sure hosts[*].modules always exists.
Waqas Hussain <waqas20@gmail.com>
parents:
5134
diff
changeset
|
251 modules = {}, |
7190
7a14ea196db3
prosodyctl: Create host.sessions table, (needed by 1295e14614f4) (thanks goffi)
Kim Alvefur <zash@zash.se>
parents:
7082
diff
changeset
|
252 sessions = {}, |
3630
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
253 users = require "core.usermanager".new_null_provider(hostname) |
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
254 }; |
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
|
255 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
|
256 |
2020
24f54340a670
prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents:
1580
diff
changeset
|
257 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
|
258 hosts[hostname] = make_host(hostname); |
2020
24f54340a670
prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents:
1580
diff
changeset
|
259 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
260 |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4881
diff
changeset
|
261 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
|
262 |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4881
diff
changeset
|
263 local prosodyctl = require "util.prosodyctl" |
6784
4da860edc27c
prosodyctl: Import LuaSocket to a local, don't assume that a global will be set
Kim Alvefur <zash@zash.se>
parents:
6751
diff
changeset
|
264 local socket = require "socket" |
8198
db82ce3decee
prosody, prosodyctl: Set up TLS settings for HTTPS requests in net.http (part of fix for #659)
Kim Alvefur <zash@zash.se>
parents:
8190
diff
changeset
|
265 |
db82ce3decee
prosody, prosodyctl: Set up TLS settings for HTTPS requests in net.http (part of fix for #659)
Kim Alvefur <zash@zash.se>
parents:
8190
diff
changeset
|
266 local http = require "net.http" |
8202
85a60e863509
prosody, prosodyctl: Fix traceback if ssl config is missing (thanks lookshe and sol)
Kim Alvefur <zash@zash.se>
parents:
8198
diff
changeset
|
267 local config_ssl = config.get("*", "ssl") or {} |
8198
db82ce3decee
prosody, prosodyctl: Set up TLS settings for HTTPS requests in net.http (part of fix for #659)
Kim Alvefur <zash@zash.se>
parents:
8190
diff
changeset
|
268 local https_client = config.get("*", "client_https_ssl") |
db82ce3decee
prosody, prosodyctl: Set up TLS settings for HTTPS requests in net.http (part of fix for #659)
Kim Alvefur <zash@zash.se>
parents:
8190
diff
changeset
|
269 http.default.options.sslctx = require "core.certmanager".create_context("client_https port 0", "client", |
db82ce3decee
prosody, prosodyctl: Set up TLS settings for HTTPS requests in net.http (part of fix for #659)
Kim Alvefur <zash@zash.se>
parents:
8190
diff
changeset
|
270 { capath = config_ssl.capath, cafile = config_ssl.cafile, verify = "peer", }, https_client); |
db82ce3decee
prosody, prosodyctl: Set up TLS settings for HTTPS requests in net.http (part of fix for #659)
Kim Alvefur <zash@zash.se>
parents:
8190
diff
changeset
|
271 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
272 ----------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
273 |
8104 | 274 -- FIXME: Duplicate code waiting for util.startup |
4881
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
275 function read_version() |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
276 -- Try to determine version |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
277 local version_file = io.open((CFG_SOURCEDIR or ".").."/prosody.version"); |
6586
317ad7f1c2ba
prosodyctl: Use util.mercurial to identify hg repository and revision
Kim Alvefur <zash@zash.se>
parents:
6584
diff
changeset
|
278 prosody.version = "unknown"; |
4881
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
279 if version_file then |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
280 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
|
281 version_file:close(); |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
282 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
|
283 prosody.version = "hg:"..prosody.version; |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
284 end |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
285 else |
6586
317ad7f1c2ba
prosodyctl: Use util.mercurial to identify hg repository and revision
Kim Alvefur <zash@zash.se>
parents:
6584
diff
changeset
|
286 local hg = require"util.mercurial"; |
317ad7f1c2ba
prosodyctl: Use util.mercurial to identify hg repository and revision
Kim Alvefur <zash@zash.se>
parents:
6584
diff
changeset
|
287 local hgid = hg.check_id(CFG_SOURCEDIR or "."); |
317ad7f1c2ba
prosodyctl: Use util.mercurial to identify hg repository and revision
Kim Alvefur <zash@zash.se>
parents:
6584
diff
changeset
|
288 if hgid then prosody.version = "hg:" .. hgid; end |
4881
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
289 end |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
290 end |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
291 |
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
|
292 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
|
293 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
|
294 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
|
295 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
|
296 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
|
297 |
6324
c9730926002b
prosodyctl: Improve JID splitting and normalization for adduser/passwd/deluser
Matthew Wild <mwild1@gmail.com>
parents:
6035
diff
changeset
|
298 local jid_split = require "util.jid".prepped_split; |
c9730926002b
prosodyctl: Improve JID splitting and normalization for adduser/passwd/deluser
Matthew Wild <mwild1@gmail.com>
parents:
6035
diff
changeset
|
299 |
5384
24f4aed5824f
prosody, prosodyctl: Remove last trace of "core" \o/
Kim Alvefur <zash@zash.se>
parents:
5296
diff
changeset
|
300 local prosodyctl_timeout = (config.get("*", "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
|
301 ----------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
302 local commands = {}; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
303 local command = arg[1]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
304 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
305 function commands.adduser(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
306 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
|
307 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
|
308 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
309 end |
6324
c9730926002b
prosodyctl: Improve JID splitting and normalization for adduser/passwd/deluser
Matthew Wild <mwild1@gmail.com>
parents:
6035
diff
changeset
|
310 local user, host = jid_split(arg[1]); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
311 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
|
312 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
|
313 show_usage [[adduser user@host]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
314 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
315 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
316 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
317 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
318 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
|
319 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
320 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
321 |
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
|
322 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
|
323 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
|
324 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
|
325 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
|
326 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
327 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
328 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
|
329 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
|
330 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
331 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
332 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
333 local password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
334 if not password then return 1; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
335 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
336 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
337 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
338 if ok then return 0; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
339 |
3777
5ecbcef42ffb
mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents:
3773
diff
changeset
|
340 show_message(msg) |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
341 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
342 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
343 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
344 function commands.passwd(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
345 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
|
346 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
|
347 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
348 end |
5610
f73d5fb4ea13
prosodyctl: Use jid.split() to parse parameter to adduser/deluser/passwd
Matthew Wild <mwild1@gmail.com>
parents:
5592
diff
changeset
|
349 local user, host = jid_split(arg[1]); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
350 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
|
351 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
|
352 show_usage [[passwd user@host]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
353 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
354 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
355 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
356 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
357 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
|
358 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
359 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
360 |
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
|
361 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
|
362 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
|
363 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
|
364 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
|
365 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
366 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
367 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
|
368 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
|
369 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
370 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
371 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
372 local password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
373 if not password then return 1; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
374 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
375 local ok, msg = prosodyctl.passwd { user = user, host = host, password = password }; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
376 |
1087
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 |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
378 |
1087
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 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
383 function commands.deluser(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
384 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
|
385 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
|
386 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
387 end |
6324
c9730926002b
prosodyctl: Improve JID splitting and normalization for adduser/passwd/deluser
Matthew Wild <mwild1@gmail.com>
parents:
6035
diff
changeset
|
388 local user, host = jid_split(arg[1]); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
389 if not user and host then |
7676
7311dc843718
prosodyctl: Fix copy/paste error in help text for deluser command
Matthew Wild <mwild1@gmail.com>
parents:
6498
diff
changeset
|
390 show_message [[Failed to understand JID, please supply the JID to the user account you want to delete]] |
7311dc843718
prosodyctl: Fix copy/paste error in help text for deluser command
Matthew Wild <mwild1@gmail.com>
parents:
6498
diff
changeset
|
391 show_usage [[deluser user@host]] |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
392 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
393 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
394 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
395 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
396 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
|
397 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
398 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
399 |
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
|
400 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
|
401 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
|
402 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
|
403 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
|
404 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
405 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
|
406 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
|
407 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
408 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
409 |
5101
a94c43cad081
prosodyctl: Use util.prosodyctl.deluser
Kim Alvefur <zash@zash.se>
parents:
5024
diff
changeset
|
410 local ok, msg = prosodyctl.deluser { user = user, host = host }; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
411 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
412 if ok then return 0; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
413 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
414 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
415 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
416 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
417 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
418 function commands.start(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
419 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
420 show_usage([[start]], [[Start Prosody]]); |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
421 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
422 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
423 local ok, ret = prosodyctl.isrunning(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
424 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
425 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
426 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
427 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
428 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
429 if ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
430 local ok, ret = prosodyctl.getpid(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
431 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
432 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
|
433 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
434 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
435 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
436 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
|
437 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
438 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
439 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
440 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
|
441 if ok then |
6062
6cc6b4d407df
prosodyctl, util.prosodyctl: Update to reflect that mod_posix gets loaded by default on posix platforms
Kim Alvefur <zash@zash.se>
parents:
6038
diff
changeset
|
442 local daemonize = config.get("*", "daemonize"); |
6cc6b4d407df
prosodyctl, util.prosodyctl: Update to reflect that mod_posix gets loaded by default on posix platforms
Kim Alvefur <zash@zash.se>
parents:
6038
diff
changeset
|
443 if daemonize == nil then |
6cc6b4d407df
prosodyctl, util.prosodyctl: Update to reflect that mod_posix gets loaded by default on posix platforms
Kim Alvefur <zash@zash.se>
parents:
6038
diff
changeset
|
444 daemonize = prosody.installed; |
6cc6b4d407df
prosodyctl, util.prosodyctl: Update to reflect that mod_posix gets loaded by default on posix platforms
Kim Alvefur <zash@zash.se>
parents:
6038
diff
changeset
|
445 end |
6cc6b4d407df
prosodyctl, util.prosodyctl: Update to reflect that mod_posix gets loaded by default on posix platforms
Kim Alvefur <zash@zash.se>
parents:
6038
diff
changeset
|
446 if daemonize 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
|
447 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
|
448 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
|
449 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
|
450 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
|
451 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
|
452 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
|
453 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
|
454 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
|
455 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
|
456 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
|
457 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
|
458 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
|
459 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
|
460 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
|
461 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
|
462 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
|
463 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
|
464 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
465 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
466 show_message("Failed to start Prosody"); |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
467 show_message(error_messages[ret]) |
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
468 return 1; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
469 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
470 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
471 function commands.status(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
472 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
473 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
|
474 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
475 end |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
476 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
477 local ok, ret = prosodyctl.isrunning(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
478 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
479 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
480 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
481 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
482 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
483 if ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
484 local ok, ret = prosodyctl.getpid(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
485 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
486 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
|
487 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
488 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
489 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
490 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
|
491 return 0; |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
492 else |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
493 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
|
494 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
|
495 print("\nNote:") |
07b2b5942957
prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents:
1120
diff
changeset
|
496 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
|
497 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
|
498 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
|
499 end |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
500 return 2 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
501 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
502 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
503 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
504 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
505 function commands.stop(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
506 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
507 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
|
508 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
509 end |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
510 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
511 if not prosodyctl.isrunning() then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
512 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
|
513 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
514 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
515 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
516 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
|
517 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
|
518 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
|
519 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
|
520 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
|
521 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
|
522 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
|
523 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
|
524 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
|
525 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
|
526 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
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 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
|
533 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
|
534 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
535 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
536 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
|
537 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
538 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
539 |
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
540 function commands.restart(arg) |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
541 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
|
542 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
|
543 return 1; |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
544 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
545 |
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
|
546 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
|
547 return commands.start(arg); |
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
548 end |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
549 |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
550 function commands.about(arg) |
4881
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
551 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
|
552 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
|
553 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
|
554 return 1; |
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
555 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
556 |
6584
c3a56f8847ac
prosodyctl: Show relative paths in about
Kim Alvefur <zash@zash.se>
parents:
6501
diff
changeset
|
557 local pwd = "."; |
6587
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
558 local lfs = require "lfs"; |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4881
diff
changeset
|
559 local array = require "util.array"; |
4815
04e6115e060b
prosodyctl: Fix import of util.iterators
Kim Alvefur <zash@zash.se>
parents:
4487
diff
changeset
|
560 local keys = require "util.iterators".keys; |
6587
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
561 local hg = require"util.mercurial"; |
6584
c3a56f8847ac
prosodyctl: Show relative paths in about
Kim Alvefur <zash@zash.se>
parents:
6501
diff
changeset
|
562 local relpath = config.resolve_relative_path; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
563 |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
564 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
|
565 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
566 print("# Prosody directories"); |
6584
c3a56f8847ac
prosodyctl: Show relative paths in about
Kim Alvefur <zash@zash.se>
parents:
6501
diff
changeset
|
567 print("Data directory: "..relpath(pwd, data_path)); |
c3a56f8847ac
prosodyctl: Show relative paths in about
Kim Alvefur <zash@zash.se>
parents:
6501
diff
changeset
|
568 print("Config directory: "..relpath(pwd, CFG_CONFIGDIR or ".")); |
c3a56f8847ac
prosodyctl: Show relative paths in about
Kim Alvefur <zash@zash.se>
parents:
6501
diff
changeset
|
569 print("Source directory: "..relpath(pwd, CFG_SOURCEDIR or ".")); |
6587
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
570 print("Plugin directories:") |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
571 print(" "..(prosody.paths.plugins:gsub("([^;]+);?", function(path) |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
572 path = config.resolve_relative_path(pwd, path); |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
573 local hgid, hgrepo = hg.check_id(path); |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
574 if not hgid and hgrepo then |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
575 return path.." - "..hgrepo .."!\n "; |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
576 end |
6611
65dd3770bcb0
prosodyctl: Document magic commit ID
Paul Aurich <paul@darkrain42.org>
parents:
6587
diff
changeset
|
577 -- 010452cfaf53 is the first commit in the prosody-modules repository |
6587
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
578 hgrepo = hgrepo == "010452cfaf53" and "prosody-modules"; |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
579 return path..(hgid and " - "..(hgrepo or "HG").." rev: "..hgid or "") |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
580 .."\n "; |
54306208f30b
prosodyctl: Expand plugin paths and attempt to identify prosody-modules checkouts
Kim Alvefur <zash@zash.se>
parents:
6586
diff
changeset
|
581 end))); |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
582 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
583 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
|
584 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
|
585 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
586 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
|
587 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
|
588 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
|
589 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
590 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
591 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
|
592 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
|
593 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
|
594 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
595 print(""); |
6498
ce66fe13eebe
prosodyctl: Fix nil global access traceback in `prosodyctl about` (luarocks 2.2.0 no longer uses module())
Waqas Hussain <waqas20@gmail.com>
parents:
6356
diff
changeset
|
596 local luarocks_status = (pcall(require, "luarocks.loader") and "Installed ("..(package.loaded["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
|
597 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
|
598 or "Not installed"; |
040193dead77
prosodyctl: Add info about the presence of LuaRocks to 'about' command
Matthew Wild <mwild1@gmail.com>
parents:
4331
diff
changeset
|
599 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
|
600 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
|
601 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
|
602 local module_versions, longest_name = {}, 8; |
6711
76683a3f3d75
prosodyctl: Soft-require LuaSec and LuaEvent so they show up in the module version listing
Kim Alvefur <zash@zash.se>
parents:
6637
diff
changeset
|
603 local luaevent =dependencies.softreq"luaevent"; |
76683a3f3d75
prosodyctl: Soft-require LuaSec and LuaEvent so they show up in the module version listing
Kim Alvefur <zash@zash.se>
parents:
6637
diff
changeset
|
604 local ssl = dependencies.softreq"ssl"; |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
605 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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
611 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
|
612 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
613 end |
7249
c49f69bb68f7
prosodyctl: Include libevent version in "about" output if luaevent is available
Kim Alvefur <zash@zash.se>
parents:
7213
diff
changeset
|
614 if luaevent then |
c49f69bb68f7
prosodyctl: Include libevent version in "about" output if luaevent is available
Kim Alvefur <zash@zash.se>
parents:
7213
diff
changeset
|
615 module_versions["libevent"] = luaevent.core.libevent_version(); |
c49f69bb68f7
prosodyctl: Include libevent version in "about" output if luaevent is available
Kim Alvefur <zash@zash.se>
parents:
7213
diff
changeset
|
616 end |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
617 local sorted_keys = array.collect(keys(module_versions)):sort(); |
7250
6ffc9247417a
prosodyctl: Use already sorted array of module names [luacheck]
Kim Alvefur <zash@zash.se>
parents:
7249
diff
changeset
|
618 for _, name in ipairs(sorted_keys) do |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
619 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
|
620 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
621 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
622 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
623 |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
624 function commands.reload(arg) |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
625 if arg[1] == "--help" then |
4476
53ce21286b8c
prosodyctl: Adjust description of 'reload' command (thanks crocket)
Matthew Wild <mwild1@gmail.com>
parents:
4336
diff
changeset
|
626 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
|
627 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
628 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
629 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
630 if not prosodyctl.isrunning() then |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
631 show_message("Prosody is not running"); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
632 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
633 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
634 |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
635 local ok, ret = prosodyctl.reload(); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
636 if ok then |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
637 |
4336
abcbcb15205c
prosodyctl: Update message on reload success
Matthew Wild <mwild1@gmail.com>
parents:
4335
diff
changeset
|
638 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
|
639 return 0; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
640 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
641 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
642 show_message(error_messages[ret]); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
643 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
644 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
645 -- ejabberdctl compatibility |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
646 |
7920
1db51061342b
prosodyctl: Handle move of 'unpack' in Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
7679
diff
changeset
|
647 local unpack = table.unpack or unpack; -- luacheck: ignore 113 |
1db51061342b
prosodyctl: Handle move of 'unpack' in Lua 5.2
Kim Alvefur <zash@zash.se>
parents:
7679
diff
changeset
|
648 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
649 function commands.register(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
650 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
|
651 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
|
652 if user ~= "--help" then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
653 if not user then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
654 show_message [[No username specified]] |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
655 elseif not host then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
656 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
|
657 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
658 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
659 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
|
660 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
661 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
662 if not password then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
663 password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
664 if not password then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
665 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
|
666 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
667 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
668 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
669 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
670 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
671 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
672 if ok then return 0; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
673 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
674 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
675 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
676 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
677 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
678 function commands.unregister(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
679 local user, host = unpack(arg); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
680 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
|
681 if user ~= "--help" then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
682 if not user then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
683 show_message [[No username specified]] |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
684 elseif not host then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
685 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
|
686 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
687 end |
1102
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
688 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
|
689 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
690 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
691 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
692 local ok, msg = prosodyctl.deluser { user = user, host = host }; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
693 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
694 if ok then return 0; end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
695 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
696 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
697 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
698 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
699 |
5292
46fbb5f1ef0a
prosodyctl: Load LFS and util.openssl when actually needed (fixes unhelpful warnings if no LuaSec installed)
Kim Alvefur <zash@zash.se>
parents:
5152
diff
changeset
|
700 local openssl; |
46fbb5f1ef0a
prosodyctl: Load LFS and util.openssl when actually needed (fixes unhelpful warnings if no LuaSec installed)
Kim Alvefur <zash@zash.se>
parents:
5152
diff
changeset
|
701 local lfs; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
702 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
703 local cert_commands = {}; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
704 |
6837
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
705 -- If a file already exists, ask if the user wants to use it or replace it |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
706 -- Backups the old file if replaced |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
707 local function use_existing(filename) |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
708 local attrs = lfs.attributes(filename); |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
709 if attrs then |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
710 if show_yesno(filename .. " exists, do you want to replace it? [y/n]") then |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
711 local backup = filename..".bkp~"..os.date("%FT%T", attrs.change); |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
712 os.rename(filename, backup); |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
713 show_message(filename.." backed up to "..backup); |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
714 else |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
715 -- Use the existing file |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
716 return true; |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
717 end |
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
718 end |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
719 end |
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
720 |
8100
1773559b03a8
prosodyctl cert: If running as root, write certificate files to config directory (fixes #530)
Kim Alvefur <zash@zash.se>
parents:
8099
diff
changeset
|
721 local cert_basedir = CFG_DATADIR or "./certs"; |
1773559b03a8
prosodyctl cert: If running as root, write certificate files to config directory (fixes #530)
Kim Alvefur <zash@zash.se>
parents:
8099
diff
changeset
|
722 if have_pposix and pposix.getuid() == 0 then |
1773559b03a8
prosodyctl cert: If running as root, write certificate files to config directory (fixes #530)
Kim Alvefur <zash@zash.se>
parents:
8099
diff
changeset
|
723 -- FIXME should be enough to check if this directory is writable |
1773559b03a8
prosodyctl cert: If running as root, write certificate files to config directory (fixes #530)
Kim Alvefur <zash@zash.se>
parents:
8099
diff
changeset
|
724 local cert_dir = config.get("*", "certificates") or "certs"; |
8102
927b9c5cc17a
prosodyctl: Use the correct variable
Kim Alvefur <zash@zash.se>
parents:
8100
diff
changeset
|
725 cert_basedir = config.resolve_relative_path(prosody.paths.config, cert_dir); |
8100
1773559b03a8
prosodyctl cert: If running as root, write certificate files to config directory (fixes #530)
Kim Alvefur <zash@zash.se>
parents:
8099
diff
changeset
|
726 end |
1773559b03a8
prosodyctl cert: If running as root, write certificate files to config directory (fixes #530)
Kim Alvefur <zash@zash.se>
parents:
8099
diff
changeset
|
727 |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
728 function cert_commands.config(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
729 if #arg >= 1 and arg[1] ~= "--help" then |
8100
1773559b03a8
prosodyctl cert: If running as root, write certificate files to config directory (fixes #530)
Kim Alvefur <zash@zash.se>
parents:
8099
diff
changeset
|
730 local conf_filename = cert_basedir .. "/" .. arg[1] .. ".cnf"; |
6837
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
731 if use_existing(conf_filename) then |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
732 return nil, conf_filename; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
733 end |
7193
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
734 local distinguished_name; |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
735 if arg[#arg]:find("^/") then |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
736 distinguished_name = table.remove(arg); |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
737 end |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
738 local conf = openssl.config.new(); |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
739 conf:from_prosody(hosts, config, arg); |
7193
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
740 if distinguished_name then |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
741 local dn = {}; |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
742 for k, v in distinguished_name:gmatch("/([^=/]+)=([^/]+)") do |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
743 table.insert(dn, k); |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
744 dn[k] = v; |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
745 end |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
746 conf.distinguished_name = dn; |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
747 else |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
748 show_message("Please provide details to include in the certificate config file."); |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
749 show_message("Leave the field empty to use the default value or '.' to exclude the field.") |
7483
8c5320a4bfaf
prosodyctl: remove unused one-letter loop variable [luacheck]
Anton Shestakov <av6@dwimlabs.net>
parents:
7455
diff
changeset
|
750 for _, k in ipairs(openssl._DN_order) do |
7193
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
751 local v = conf.distinguished_name[k]; |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
752 if v then |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
753 local nv; |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
754 if k == "commonName" then |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
755 v = arg[1] |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
756 elseif k == "emailAddress" then |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
757 v = "xmpp@" .. arg[1]; |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
758 elseif k == "countryName" then |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
759 local tld = arg[1]:match"%.([a-z]+)$"; |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
760 if tld and #tld == 2 and tld ~= "uk" then |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
761 v = tld:upper(); |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
762 end |
5547
f306daf2bf6d
prosodyctl: Guess the country from the TLD for the cert config
Kim Alvefur <zash@zash.se>
parents:
5546
diff
changeset
|
763 end |
7193
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
764 nv = show_prompt(("%s (%s):"):format(k, nv or v)); |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
765 nv = (not nv or nv == "") and v or nv; |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
766 if nv:find"[\192-\252][\128-\191]+" then |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
767 conf.req.string_mask = "utf8only" |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
768 end |
1c0104a56321
prosodyctl: Allow a DN path to be given to 'cert generate' command (fixes #349)
Kim Alvefur <zash@zash.se>
parents:
7190
diff
changeset
|
769 conf.distinguished_name[k] = nv ~= "." and nv or nil; |
5546
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
770 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
771 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
772 end |
6035
1b5ca55bf895
prosodyctl: Show real error if certificate config file can't be opened
Kim Alvefur <zash@zash.se>
parents:
5547
diff
changeset
|
773 local conf_file, err = io.open(conf_filename, "w"); |
1b5ca55bf895
prosodyctl: Show real error if certificate config file can't be opened
Kim Alvefur <zash@zash.se>
parents:
5547
diff
changeset
|
774 if not conf_file then |
1b5ca55bf895
prosodyctl: Show real error if certificate config file can't be opened
Kim Alvefur <zash@zash.se>
parents:
5547
diff
changeset
|
775 show_warning("Could not open OpenSSL config file for writing"); |
1b5ca55bf895
prosodyctl: Show real error if certificate config file can't be opened
Kim Alvefur <zash@zash.se>
parents:
5547
diff
changeset
|
776 show_warning(err); |
1b5ca55bf895
prosodyctl: Show real error if certificate config file can't be opened
Kim Alvefur <zash@zash.se>
parents:
5547
diff
changeset
|
777 os.exit(1); |
1b5ca55bf895
prosodyctl: Show real error if certificate config file can't be opened
Kim Alvefur <zash@zash.se>
parents:
5547
diff
changeset
|
778 end |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
779 conf_file:write(conf:serialize()); |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
780 conf_file:close(); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
781 print(""); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
782 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
|
783 return nil, conf_filename; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
784 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
785 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
|
786 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
787 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
788 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
789 function cert_commands.key(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
790 if #arg >= 1 and arg[1] ~= "--help" then |
8100
1773559b03a8
prosodyctl cert: If running as root, write certificate files to config directory (fixes #530)
Kim Alvefur <zash@zash.se>
parents:
8099
diff
changeset
|
791 local key_filename = cert_basedir .. "/" .. arg[1] .. ".key"; |
6837
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
792 if use_existing(key_filename) then |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
793 return nil, key_filename; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
794 end |
5151
dfe6a70efaa2
prosodyctl: Set stricter umask while generating key (thanks darkrain)
Kim Alvefur <zash@zash.se>
parents:
5150
diff
changeset
|
795 os.remove(key_filename); -- This file, if it exists is unlikely to have write permissions |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
796 local key_size = tonumber(arg[2] or show_prompt("Choose key size (2048):") or 2048); |
5151
dfe6a70efaa2
prosodyctl: Set stricter umask while generating key (thanks darkrain)
Kim Alvefur <zash@zash.se>
parents:
5150
diff
changeset
|
797 local old_umask = pposix.umask("0377"); |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
798 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
|
799 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
|
800 show_message("Key written to ".. key_filename); |
5151
dfe6a70efaa2
prosodyctl: Set stricter umask while generating key (thanks darkrain)
Kim Alvefur <zash@zash.se>
parents:
5150
diff
changeset
|
801 pposix.umask(old_umask); |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
802 return nil, key_filename; |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
803 end |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
804 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
|
805 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
806 show_usage("cert key HOSTNAME <bits>", "Generates a RSA key named HOSTNAME.key\n " |
4935 | 807 .."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
|
808 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
809 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
810 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
811 function cert_commands.request(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
812 if #arg >= 1 and arg[1] ~= "--help" then |
8100
1773559b03a8
prosodyctl cert: If running as root, write certificate files to config directory (fixes #530)
Kim Alvefur <zash@zash.se>
parents:
8099
diff
changeset
|
813 local req_filename = cert_basedir .. "/" .. arg[1] .. ".req"; |
6837
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
814 if use_existing(req_filename) then |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
815 return nil, req_filename; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
816 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
817 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
|
818 local _, conf_filename = cert_commands.config(arg); |
6405
61801dacc90b
prosodyctl: Use sha256 for certificate requests and self-signed certificates
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
819 if openssl.req{new=true, key=key_filename, utf8=true, sha256=true, config=conf_filename, out=req_filename} then |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
820 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
|
821 else |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
822 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
|
823 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
824 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
825 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
|
826 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
827 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
828 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
829 function cert_commands.generate(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
830 if #arg >= 1 and arg[1] ~= "--help" then |
8100
1773559b03a8
prosodyctl cert: If running as root, write certificate files to config directory (fixes #530)
Kim Alvefur <zash@zash.se>
parents:
8099
diff
changeset
|
831 local cert_filename = cert_basedir .. "/" .. arg[1] .. ".crt"; |
6837
13b44929ae49
prosodyctl: Move files out of the way when generating new cert or key
Kim Alvefur <zash@zash.se>
parents:
6784
diff
changeset
|
832 if use_existing(cert_filename) then |
5152
fee5f8d4ec74
prosodyctl: Fix copypaste error
Kim Alvefur <zash@zash.se>
parents:
5151
diff
changeset
|
833 return nil, cert_filename; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
834 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
835 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
|
836 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
|
837 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
|
838 and openssl.req{new=true, x509=true, nodes=true, key=key_filename, |
6405
61801dacc90b
prosodyctl: Use sha256 for certificate requests and self-signed certificates
Kim Alvefur <zash@zash.se>
parents:
6367
diff
changeset
|
839 days=365, sha256=true, utf8=true, config=conf_filename, out=cert_filename} then |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
840 show_message("Certificate written to ".. cert_filename); |
7065
4fc3c008976f
prosodyctl: Show an example ssl config after generating a certificate
Kim Alvefur <zash@zash.se>
parents:
6960
diff
changeset
|
841 print(); |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
842 else |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
843 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
|
844 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
845 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
846 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
|
847 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
848 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
849 |
8111
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
850 local function sh_esc(s) |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
851 return "'" .. s:gsub("'", "'\\''") .. "'"; |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
852 end |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
853 |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
854 local function copy(from, to, umask, owner, group) |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
855 local old_umask = umask and pposix.umask(umask); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
856 local attrs = lfs.attributes(to); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
857 if attrs then -- Move old file out of the way |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
858 local backup = to..".bkp~"..os.date("%FT%T", attrs.change); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
859 os.rename(to, backup); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
860 end |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
861 -- FIXME friendlier error handling, maybe move above backup back? |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
862 local input = assert(io.open(from)); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
863 local output = assert(io.open(to, "w")); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
864 local data = input:read(2^11); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
865 while data and output:write(data) do |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
866 data = input:read(2^11); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
867 end |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
868 assert(input:close()); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
869 assert(output:close()); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
870 if owner and group then |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
871 local ok = os.execute(("chown %s.%s %s"):format(sh_esc(owner), sh_esc(group), sh_esc(to))); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
872 assert(ok == true or ok == 0, "Failed to change ownership of "..to); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
873 end |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
874 if old_umask then pposix.umask(old_umask); end |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
875 return true; |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
876 end |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
877 |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
878 function cert_commands.import(arg) |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
879 local hostnames = {}; |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
880 -- Move hostname arguments out of arg, the rest should be a list of paths |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
881 while arg[1] and prosody.hosts[ arg[1] ] do |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
882 table.insert(hostnames, table.remove(arg, 1)); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
883 end |
8247
2c386ee5cd5c
prosodyctl: Use all enabled hosts if no hostnames passed to cert import
Kim Alvefur <zash@zash.se>
parents:
8202
diff
changeset
|
884 if hostnames[1] == nil then |
8249
cc664a3917e2
prosodyctl: cert import: Use env variable set by certbot if invoked as post-renew hook
Kim Alvefur <zash@zash.se>
parents:
8248
diff
changeset
|
885 local domains = os.getenv"RENEWED_DOMAINS"; -- Set if invoked via certbot |
cc664a3917e2
prosodyctl: cert import: Use env variable set by certbot if invoked as post-renew hook
Kim Alvefur <zash@zash.se>
parents:
8248
diff
changeset
|
886 if domains then |
cc664a3917e2
prosodyctl: cert import: Use env variable set by certbot if invoked as post-renew hook
Kim Alvefur <zash@zash.se>
parents:
8248
diff
changeset
|
887 for host in domains:gmatch("%S+") do |
8247
2c386ee5cd5c
prosodyctl: Use all enabled hosts if no hostnames passed to cert import
Kim Alvefur <zash@zash.se>
parents:
8202
diff
changeset
|
888 table.insert(hostnames, host); |
2c386ee5cd5c
prosodyctl: Use all enabled hosts if no hostnames passed to cert import
Kim Alvefur <zash@zash.se>
parents:
8202
diff
changeset
|
889 end |
8249
cc664a3917e2
prosodyctl: cert import: Use env variable set by certbot if invoked as post-renew hook
Kim Alvefur <zash@zash.se>
parents:
8248
diff
changeset
|
890 else |
cc664a3917e2
prosodyctl: cert import: Use env variable set by certbot if invoked as post-renew hook
Kim Alvefur <zash@zash.se>
parents:
8248
diff
changeset
|
891 for host in pairs(prosody.hosts) do |
cc664a3917e2
prosodyctl: cert import: Use env variable set by certbot if invoked as post-renew hook
Kim Alvefur <zash@zash.se>
parents:
8248
diff
changeset
|
892 if host ~= "*" and config.get(host, "enabled") ~= false then |
cc664a3917e2
prosodyctl: cert import: Use env variable set by certbot if invoked as post-renew hook
Kim Alvefur <zash@zash.se>
parents:
8248
diff
changeset
|
893 table.insert(hostnames, host); |
cc664a3917e2
prosodyctl: cert import: Use env variable set by certbot if invoked as post-renew hook
Kim Alvefur <zash@zash.se>
parents:
8248
diff
changeset
|
894 end |
cc664a3917e2
prosodyctl: cert import: Use env variable set by certbot if invoked as post-renew hook
Kim Alvefur <zash@zash.se>
parents:
8248
diff
changeset
|
895 end |
8247
2c386ee5cd5c
prosodyctl: Use all enabled hosts if no hostnames passed to cert import
Kim Alvefur <zash@zash.se>
parents:
8202
diff
changeset
|
896 end |
2c386ee5cd5c
prosodyctl: Use all enabled hosts if no hostnames passed to cert import
Kim Alvefur <zash@zash.se>
parents:
8202
diff
changeset
|
897 end |
8111
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
898 if not arg[1] or arg[1] == "--help" then -- Probably forgot the path |
8247
2c386ee5cd5c
prosodyctl: Use all enabled hosts if no hostnames passed to cert import
Kim Alvefur <zash@zash.se>
parents:
8202
diff
changeset
|
899 show_usage("cert import [HOSTNAME+] /path/to/certs [/other/paths/]+", |
8111
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
900 "Copies certificates to "..cert_basedir); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
901 return 1; |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
902 end |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
903 local owner, group; |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
904 if pposix.getuid() == 0 then -- We need root to change ownership |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
905 owner = config.get("*", "prosody_user") or "prosody"; |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
906 group = config.get("*", "prosody_group") or owner; |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
907 end |
8274
3798955049e3
prosodyctl: cert import: Reuse function from certmanager for locating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
8265
diff
changeset
|
908 local cm = require "core.certmanager"; |
8117
66d8f6b3c3ef
prosodyctl: Delay reporting of successful certificate imports until all done
Kim Alvefur <zash@zash.se>
parents:
8111
diff
changeset
|
909 local imported = {}; |
8111
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
910 for _, host in ipairs(hostnames) do |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
911 for _, dir in ipairs(arg) do |
8274
3798955049e3
prosodyctl: cert import: Reuse function from certmanager for locating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
8265
diff
changeset
|
912 local paths = cm.find_cert(dir, host); |
3798955049e3
prosodyctl: cert import: Reuse function from certmanager for locating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
8265
diff
changeset
|
913 if paths then |
3798955049e3
prosodyctl: cert import: Reuse function from certmanager for locating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
8265
diff
changeset
|
914 copy(paths.certificate, cert_basedir .. "/" .. host .. ".crt", nil, owner, group); |
3798955049e3
prosodyctl: cert import: Reuse function from certmanager for locating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
8265
diff
changeset
|
915 copy(paths.key, cert_basedir .. "/" .. host .. ".key", "0377", owner, group); |
8117
66d8f6b3c3ef
prosodyctl: Delay reporting of successful certificate imports until all done
Kim Alvefur <zash@zash.se>
parents:
8111
diff
changeset
|
916 table.insert(imported, host); |
8111
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
917 else |
8119
94a1fdaf12d1
prosodyctl: Make note about reporting where certificates are searched for
Kim Alvefur <zash@zash.se>
parents:
8118
diff
changeset
|
918 -- TODO Say where we looked |
8111
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
919 show_warning("No certificate for host "..host.." found :("); |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
920 end |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
921 -- TODO Additional checks |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
922 -- Certificate names matches the hostname |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
923 -- Private key matches public key in certificate |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
924 end |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
925 end |
8117
66d8f6b3c3ef
prosodyctl: Delay reporting of successful certificate imports until all done
Kim Alvefur <zash@zash.se>
parents:
8111
diff
changeset
|
926 if imported[1] then |
66d8f6b3c3ef
prosodyctl: Delay reporting of successful certificate imports until all done
Kim Alvefur <zash@zash.se>
parents:
8111
diff
changeset
|
927 show_message("Imported certificate and key for hosts "..table.concat(imported, ", ")); |
8120
3c5f0cb4381a
prosodyctl: Attempt to reload prosody after importing certificates
Kim Alvefur <zash@zash.se>
parents:
8119
diff
changeset
|
928 local ok, err = prosodyctl.reload(); |
3c5f0cb4381a
prosodyctl: Attempt to reload prosody after importing certificates
Kim Alvefur <zash@zash.se>
parents:
8119
diff
changeset
|
929 if not ok and err ~= "not-running" then |
3c5f0cb4381a
prosodyctl: Attempt to reload prosody after importing certificates
Kim Alvefur <zash@zash.se>
parents:
8119
diff
changeset
|
930 show_message(error_messages[err]); |
3c5f0cb4381a
prosodyctl: Attempt to reload prosody after importing certificates
Kim Alvefur <zash@zash.se>
parents:
8119
diff
changeset
|
931 end |
8118
f8c52010bd37
prosodyctl: Return non-zero exit code from cert import if no certificates imported
Kim Alvefur <zash@zash.se>
parents:
8117
diff
changeset
|
932 else |
f8c52010bd37
prosodyctl: Return non-zero exit code from cert import if no certificates imported
Kim Alvefur <zash@zash.se>
parents:
8117
diff
changeset
|
933 show_warning("No certificates imported :("); |
f8c52010bd37
prosodyctl: Return non-zero exit code from cert import if no certificates imported
Kim Alvefur <zash@zash.se>
parents:
8117
diff
changeset
|
934 return 1; |
8117
66d8f6b3c3ef
prosodyctl: Delay reporting of successful certificate imports until all done
Kim Alvefur <zash@zash.se>
parents:
8111
diff
changeset
|
935 end |
8111
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
936 end |
3cbb311f8468
prosodyctl: cert import: Command to copy certificates into prosodys certificate directory (fixes #892)
Kim Alvefur <zash@zash.se>
parents:
8110
diff
changeset
|
937 |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
938 function commands.cert(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
939 if #arg >= 1 and arg[1] ~= "--help" then |
5292
46fbb5f1ef0a
prosodyctl: Load LFS and util.openssl when actually needed (fixes unhelpful warnings if no LuaSec installed)
Kim Alvefur <zash@zash.se>
parents:
5152
diff
changeset
|
940 openssl = require "util.openssl"; |
46fbb5f1ef0a
prosodyctl: Load LFS and util.openssl when actually needed (fixes unhelpful warnings if no LuaSec installed)
Kim Alvefur <zash@zash.se>
parents:
5152
diff
changeset
|
941 lfs = require "lfs"; |
8107
83d776b344ad
prosodyctl: Verify permissions on directory that certificates are written to
Kim Alvefur <zash@zash.se>
parents:
8106
diff
changeset
|
942 local cert_dir_attrs = lfs.attributes(cert_basedir); |
8108
939ccedb509d
prosodyctl: Verify that directory certs are written to exists
Kim Alvefur <zash@zash.se>
parents:
8107
diff
changeset
|
943 if not cert_dir_attrs then |
939ccedb509d
prosodyctl: Verify that directory certs are written to exists
Kim Alvefur <zash@zash.se>
parents:
8107
diff
changeset
|
944 show_warning("The directory "..cert_basedir.." does not exist"); |
939ccedb509d
prosodyctl: Verify that directory certs are written to exists
Kim Alvefur <zash@zash.se>
parents:
8107
diff
changeset
|
945 return 1; -- TODO Should we create it? |
939ccedb509d
prosodyctl: Verify that directory certs are written to exists
Kim Alvefur <zash@zash.se>
parents:
8107
diff
changeset
|
946 end |
8107
83d776b344ad
prosodyctl: Verify permissions on directory that certificates are written to
Kim Alvefur <zash@zash.se>
parents:
8106
diff
changeset
|
947 if pposix.getuid() ~= cert_dir_attrs.uid then |
83d776b344ad
prosodyctl: Verify permissions on directory that certificates are written to
Kim Alvefur <zash@zash.se>
parents:
8106
diff
changeset
|
948 show_warning("The directory "..cert_basedir.." is not owned by the current user, won't be able to write files to it"); |
83d776b344ad
prosodyctl: Verify permissions on directory that certificates are written to
Kim Alvefur <zash@zash.se>
parents:
8106
diff
changeset
|
949 return 1; |
83d776b344ad
prosodyctl: Verify permissions on directory that certificates are written to
Kim Alvefur <zash@zash.se>
parents:
8106
diff
changeset
|
950 elseif cert_dir_attrs.permissions:match("^%.w..%-..%-.$") then |
83d776b344ad
prosodyctl: Verify permissions on directory that certificates are written to
Kim Alvefur <zash@zash.se>
parents:
8106
diff
changeset
|
951 show_warning("The directory "..cert_basedir.." not only writable by its owner"); |
83d776b344ad
prosodyctl: Verify permissions on directory that certificates are written to
Kim Alvefur <zash@zash.se>
parents:
8106
diff
changeset
|
952 return 1; |
83d776b344ad
prosodyctl: Verify permissions on directory that certificates are written to
Kim Alvefur <zash@zash.se>
parents:
8106
diff
changeset
|
953 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
954 local subcmd = table.remove(arg, 1); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
955 if type(cert_commands[subcmd]) == "function" then |
8248
259e0010a6d4
prosodyctl: Only demand a hostname argument to cert commands other than import
Kim Alvefur <zash@zash.se>
parents:
8247
diff
changeset
|
956 if subcmd ~= "import" then -- hostnames are optional for import |
259e0010a6d4
prosodyctl: Only demand a hostname argument to cert commands other than import
Kim Alvefur <zash@zash.se>
parents:
8247
diff
changeset
|
957 if not arg[1] then |
259e0010a6d4
prosodyctl: Only demand a hostname argument to cert commands other than import
Kim Alvefur <zash@zash.se>
parents:
8247
diff
changeset
|
958 show_message"You need to supply at least one hostname" |
259e0010a6d4
prosodyctl: Only demand a hostname argument to cert commands other than import
Kim Alvefur <zash@zash.se>
parents:
8247
diff
changeset
|
959 arg = { "--help" }; |
259e0010a6d4
prosodyctl: Only demand a hostname argument to cert commands other than import
Kim Alvefur <zash@zash.se>
parents:
8247
diff
changeset
|
960 end |
259e0010a6d4
prosodyctl: Only demand a hostname argument to cert commands other than import
Kim Alvefur <zash@zash.se>
parents:
8247
diff
changeset
|
961 if arg[1] ~= "--help" and not hosts[arg[1]] then |
259e0010a6d4
prosodyctl: Only demand a hostname argument to cert commands other than import
Kim Alvefur <zash@zash.se>
parents:
8247
diff
changeset
|
962 show_message(error_messages["no-such-host"]); |
259e0010a6d4
prosodyctl: Only demand a hostname argument to cert commands other than import
Kim Alvefur <zash@zash.se>
parents:
8247
diff
changeset
|
963 return 1; |
259e0010a6d4
prosodyctl: Only demand a hostname argument to cert commands other than import
Kim Alvefur <zash@zash.se>
parents:
8247
diff
changeset
|
964 end |
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
|
965 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
966 return cert_commands[subcmd](arg); |
8177
f52cdad171b0
prosodyctl: Make `cert check` do the same as `check certs`
Kim Alvefur <zash@zash.se>
parents:
8144
diff
changeset
|
967 elseif subcmd == "check" then |
f52cdad171b0
prosodyctl: Make `cert check` do the same as `check certs`
Kim Alvefur <zash@zash.se>
parents:
8144
diff
changeset
|
968 return commands.check({"certs"}); |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
969 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
970 end |
8122
e56a90168890
prosodyctl: Add cert import to short help
Kim Alvefur <zash@zash.se>
parents:
8120
diff
changeset
|
971 show_usage("cert config|request|generate|key|import", "Helpers for generating X.509 certificates and keys.") |
8144
8e9a36d0c7d1
prosodyctl: Show description of each certificate subcommand
Kim Alvefur <zash@zash.se>
parents:
8122
diff
changeset
|
972 for _, cmd in pairs(cert_commands) do |
8e9a36d0c7d1
prosodyctl: Show description of each certificate subcommand
Kim Alvefur <zash@zash.se>
parents:
8122
diff
changeset
|
973 print() |
8e9a36d0c7d1
prosodyctl: Show description of each certificate subcommand
Kim Alvefur <zash@zash.se>
parents:
8122
diff
changeset
|
974 cmd{ "--help" } |
8e9a36d0c7d1
prosodyctl: Show description of each certificate subcommand
Kim Alvefur <zash@zash.se>
parents:
8122
diff
changeset
|
975 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
976 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
977 |
5584
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
978 function commands.check(arg) |
5655
6d7f7548b2c9
prosodyctl: Add 'prosodyctl check --help'
Kim Alvefur <zash@zash.se>
parents:
5620
diff
changeset
|
979 if arg[1] == "--help" then |
6d7f7548b2c9
prosodyctl: Add 'prosodyctl check --help'
Kim Alvefur <zash@zash.se>
parents:
5620
diff
changeset
|
980 show_usage([[check]], [[Perform basic checks on your Prosody installation]]); |
6d7f7548b2c9
prosodyctl: Add 'prosodyctl check --help'
Kim Alvefur <zash@zash.se>
parents:
5620
diff
changeset
|
981 return 1; |
6d7f7548b2c9
prosodyctl: Add 'prosodyctl check --help'
Kim Alvefur <zash@zash.se>
parents:
5620
diff
changeset
|
982 end |
5584
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
983 local what = table.remove(arg, 1); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
984 local array, set = require "util.array", require "util.set"; |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
985 local it = require "util.iterators"; |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
986 local ok = true; |
6158
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
987 local function disabled_hosts(host, conf) return host ~= "*" and conf.enabled ~= false; end |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
988 local function enabled_hosts() return it.filter(disabled_hosts, pairs(config.getconfig())); end |
6159
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
989 if not what or what == "disabled" then |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
990 local disabled_hosts = set.new(); |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
991 for host, host_options in it.filter("*", pairs(config.getconfig())) do |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
992 if host_options.enabled == false then |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
993 disabled_hosts:add(host); |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
994 end |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
995 end |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
996 if not disabled_hosts:empty() then |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
997 local msg = "Checks will be skipped for these disabled hosts: %s"; |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
998 if what then msg = "These hosts are disabled: %s"; end |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
999 show_warning(msg, tostring(disabled_hosts)); |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
1000 if what then return 0; end |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
1001 print"" |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
1002 end |
4ee14b7ef2cc
prosodyctl: Add check that points out any disabled hosts
Kim Alvefur <zash@zash.se>
parents:
6158
diff
changeset
|
1003 end |
5584
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1004 if not what or what == "config" then |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1005 print("Checking config..."); |
6160
cf0f7caa885e
prosodyctl: Check for deprecated config options
Kim Alvefur <zash@zash.se>
parents:
6159
diff
changeset
|
1006 local deprecated = set.new({ |
6486
64146196b142
prosodyctl: Add 'require_encryption' to list of deprecated options pointed out by the check command
Kim Alvefur <zash@zash.se>
parents:
6405
diff
changeset
|
1007 "bosh_ports", "disallow_s2s", "no_daemonize", "anonymous_login", "require_encryption", |
7267
8ad2dbc4fdb6
prosodyctl check: Add 'vcard_compatibility' to deprecated options
Kim Alvefur <zash@zash.se>
parents:
7252
diff
changeset
|
1008 "vcard_compatibility", |
6160
cf0f7caa885e
prosodyctl: Check for deprecated config options
Kim Alvefur <zash@zash.se>
parents:
6159
diff
changeset
|
1009 }); |
5584
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1010 local known_global_options = set.new({ |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1011 "pidfile", "log", "plugin_paths", "prosody_user", "prosody_group", "daemonize", |
6751
18f18bceb662
prosodyctl: check: Add some more known global config options
Kim Alvefur <zash@zash.se>
parents:
6711
diff
changeset
|
1012 "umask", "prosodyctl_timeout", "use_ipv6", "use_libevent", "network_settings", |
18f18bceb662
prosodyctl: check: Add some more known global config options
Kim Alvefur <zash@zash.se>
parents:
6711
diff
changeset
|
1013 "network_backend", "http_default_host", |
5584
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1014 }); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1015 local config = config.getconfig(); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1016 -- Check that we have any global options (caused by putting a host at the top) |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1017 if it.count(it.filter("log", pairs(config["*"]))) == 0 then |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1018 ok = false; |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1019 print(""); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1020 print(" No global options defined. Perhaps you have put a host definition at the top") |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1021 print(" of the config file? They should be at the bottom, see http://prosody.im/doc/configure#overview"); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1022 end |
6162
fbc3b195dab8
prosodyctl: Check that there is at least one enabled VirtualHost (or Component) defined
Kim Alvefur <zash@zash.se>
parents:
6161
diff
changeset
|
1023 if it.count(enabled_hosts()) == 0 then |
fbc3b195dab8
prosodyctl: Check that there is at least one enabled VirtualHost (or Component) defined
Kim Alvefur <zash@zash.se>
parents:
6161
diff
changeset
|
1024 ok = false; |
fbc3b195dab8
prosodyctl: Check that there is at least one enabled VirtualHost (or Component) defined
Kim Alvefur <zash@zash.se>
parents:
6161
diff
changeset
|
1025 print(""); |
fbc3b195dab8
prosodyctl: Check that there is at least one enabled VirtualHost (or Component) defined
Kim Alvefur <zash@zash.se>
parents:
6161
diff
changeset
|
1026 if it.count(it.filter("*", pairs(config))) == 0 then |
fbc3b195dab8
prosodyctl: Check that there is at least one enabled VirtualHost (or Component) defined
Kim Alvefur <zash@zash.se>
parents:
6161
diff
changeset
|
1027 print(" No hosts are defined, please add at least one VirtualHost section") |
fbc3b195dab8
prosodyctl: Check that there is at least one enabled VirtualHost (or Component) defined
Kim Alvefur <zash@zash.se>
parents:
6161
diff
changeset
|
1028 elseif config["*"]["enabled"] == false then |
fbc3b195dab8
prosodyctl: Check that there is at least one enabled VirtualHost (or Component) defined
Kim Alvefur <zash@zash.se>
parents:
6161
diff
changeset
|
1029 print(" No hosts are enabled. Remove enabled = false from the global section or put enabled = true under at least one VirtualHost section") |
fbc3b195dab8
prosodyctl: Check that there is at least one enabled VirtualHost (or Component) defined
Kim Alvefur <zash@zash.se>
parents:
6161
diff
changeset
|
1030 else |
fbc3b195dab8
prosodyctl: Check that there is at least one enabled VirtualHost (or Component) defined
Kim Alvefur <zash@zash.se>
parents:
6161
diff
changeset
|
1031 print(" All hosts are disabled. Remove enabled = false from at least one VirtualHost section") |
fbc3b195dab8
prosodyctl: Check that there is at least one enabled VirtualHost (or Component) defined
Kim Alvefur <zash@zash.se>
parents:
6161
diff
changeset
|
1032 end |
fbc3b195dab8
prosodyctl: Check that there is at least one enabled VirtualHost (or Component) defined
Kim Alvefur <zash@zash.se>
parents:
6161
diff
changeset
|
1033 end |
7082
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1034 if not config["*"].modules_enabled then |
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1035 print(" No global modules_enabled is set?"); |
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1036 local suggested_global_modules; |
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1037 for host, options in enabled_hosts() do |
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1038 if not options.component_module and options.modules_enabled then |
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1039 suggested_global_modules = set.intersection(suggested_global_modules or set.new(options.modules_enabled), set.new(options.modules_enabled)); |
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1040 end |
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1041 end |
8265
17ebd8ac8545
prosodyctl check: Fix traceback when no modules_enabled are defined (e.g., a completely empty config)
Waqas Hussain <waqas20@gmail.com>
parents:
8249
diff
changeset
|
1042 if suggested_global_modules and not suggested_global_modules:empty() then |
7082
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1043 print(" Consider moving these modules into modules_enabled in the global section:") |
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1044 print(" "..tostring(suggested_global_modules / function (x) return ("%q"):format(x) end)); |
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1045 end |
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1046 print(); |
8b590fc77d91
prosodyctl: check config: Suggest moving modules enabled on all hosts to a global_modules enabled if that is unset
Kim Alvefur <zash@zash.se>
parents:
7080
diff
changeset
|
1047 end |
5584
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1048 -- Check for global options under hosts |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1049 local global_options = set.new(it.to_array(it.keys(config["*"]))); |
6160
cf0f7caa885e
prosodyctl: Check for deprecated config options
Kim Alvefur <zash@zash.se>
parents:
6159
diff
changeset
|
1050 local deprecated_global_options = set.intersection(global_options, deprecated); |
cf0f7caa885e
prosodyctl: Check for deprecated config options
Kim Alvefur <zash@zash.se>
parents:
6159
diff
changeset
|
1051 if not deprecated_global_options:empty() then |
cf0f7caa885e
prosodyctl: Check for deprecated config options
Kim Alvefur <zash@zash.se>
parents:
6159
diff
changeset
|
1052 print(""); |
cf0f7caa885e
prosodyctl: Check for deprecated config options
Kim Alvefur <zash@zash.se>
parents:
6159
diff
changeset
|
1053 print(" You have some deprecated options in the global section:"); |
cf0f7caa885e
prosodyctl: Check for deprecated config options
Kim Alvefur <zash@zash.se>
parents:
6159
diff
changeset
|
1054 print(" "..tostring(deprecated_global_options)) |
cf0f7caa885e
prosodyctl: Check for deprecated config options
Kim Alvefur <zash@zash.se>
parents:
6159
diff
changeset
|
1055 ok = false; |
cf0f7caa885e
prosodyctl: Check for deprecated config options
Kim Alvefur <zash@zash.se>
parents:
6159
diff
changeset
|
1056 end |
6158
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1057 for host, options in enabled_hosts() do |
5584
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1058 local host_options = set.new(it.to_array(it.keys(options))); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1059 local misplaced_options = set.intersection(host_options, known_global_options); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1060 for name in pairs(options) do |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1061 if name:match("^interfaces?") |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1062 or name:match("_ports?$") or name:match("_interfaces?$") |
6914
5df76208e050
prosodyctl: check: Don't complain about c2s_ssl or s2s_ssl being in VirtualHost sections, that's supported
Kim Alvefur <zash@zash.se>
parents:
6845
diff
changeset
|
1063 or (name:match("_ssl$") and not name:match("^[cs]2s_ssl$")) then |
5584
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1064 misplaced_options:add(name); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1065 end |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1066 end |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1067 if not misplaced_options:empty() then |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1068 ok = false; |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1069 print(""); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1070 local n = it.count(misplaced_options); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1071 print(" You have "..n.." option"..(n>1 and "s " or " ").."set under "..host.." that should be"); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1072 print(" in the global section of the config file, above any VirtualHost or Component definitions,") |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1073 print(" see http://prosody.im/doc/configure#overview for more information.") |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1074 print(""); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1075 print(" You need to move the following option"..(n>1 and "s" or "")..": "..table.concat(it.to_array(misplaced_options), ", ")); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1076 end |
5616
a79c6717ee2b
prosodyctl: check config: Show a suggestion to change hosts that begin with jabber/xmpp/chat/im subdomains, and link to DNS documentation
Matthew Wild <mwild1@gmail.com>
parents:
5610
diff
changeset
|
1077 local subdomain = host:match("^[^.]+"); |
5619
6a87b75aedd5
prosodyctl: check config: Fix check for whether host is a component
Matthew Wild <mwild1@gmail.com>
parents:
5617
diff
changeset
|
1078 if not(host_options:contains("component_module")) and (subdomain == "jabber" or subdomain == "xmpp" |
8109
2f214c4db170
prosodyctl: Normalize inconsistent whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8108
diff
changeset
|
1079 or subdomain == "chat" or subdomain == "im") then |
2f214c4db170
prosodyctl: Normalize inconsistent whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8108
diff
changeset
|
1080 print(""); |
2f214c4db170
prosodyctl: Normalize inconsistent whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8108
diff
changeset
|
1081 print(" Suggestion: If "..host.. " is a new host with no real users yet, consider renaming it now to"); |
2f214c4db170
prosodyctl: Normalize inconsistent whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8108
diff
changeset
|
1082 print(" "..host:gsub("^[^.]+%.", "")..". You can use SRV records to redirect XMPP clients and servers to "..host.."."); |
2f214c4db170
prosodyctl: Normalize inconsistent whitespace [luacheck]
Kim Alvefur <zash@zash.se>
parents:
8108
diff
changeset
|
1083 print(" For more information see: http://prosody.im/doc/dns"); |
5616
a79c6717ee2b
prosodyctl: check config: Show a suggestion to change hosts that begin with jabber/xmpp/chat/im subdomains, and link to DNS documentation
Matthew Wild <mwild1@gmail.com>
parents:
5610
diff
changeset
|
1084 end |
5584
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1085 end |
6959
aa8647a5105d
prosodyctl check: Point out items in the modules_enabled list that incorrectly include the 'mod_' prefix
Kim Alvefur <zash@zash.se>
parents:
6958
diff
changeset
|
1086 local all_modules = set.new(config["*"].modules_enabled); |
6957
e442016918a9
prosodyctl check: Include global options when checking "all options"
Kim Alvefur <zash@zash.se>
parents:
6914
diff
changeset
|
1087 local all_options = set.new(it.to_array(it.keys(config["*"]))); |
6844
8946052e12d2
prosodyctl check: Warn if encryption is required but LuaSec is unavailable
Kim Alvefur <zash@zash.se>
parents:
6837
diff
changeset
|
1088 for host in enabled_hosts() do |
8946052e12d2
prosodyctl check: Warn if encryption is required but LuaSec is unavailable
Kim Alvefur <zash@zash.se>
parents:
6837
diff
changeset
|
1089 all_options:include(set.new(it.to_array(it.keys(config[host])))); |
6959
aa8647a5105d
prosodyctl check: Point out items in the modules_enabled list that incorrectly include the 'mod_' prefix
Kim Alvefur <zash@zash.se>
parents:
6958
diff
changeset
|
1090 all_modules:include(set.new(config[host].modules_enabled)); |
aa8647a5105d
prosodyctl check: Point out items in the modules_enabled list that incorrectly include the 'mod_' prefix
Kim Alvefur <zash@zash.se>
parents:
6958
diff
changeset
|
1091 end |
aa8647a5105d
prosodyctl check: Point out items in the modules_enabled list that incorrectly include the 'mod_' prefix
Kim Alvefur <zash@zash.se>
parents:
6958
diff
changeset
|
1092 for mod in all_modules do |
aa8647a5105d
prosodyctl check: Point out items in the modules_enabled list that incorrectly include the 'mod_' prefix
Kim Alvefur <zash@zash.se>
parents:
6958
diff
changeset
|
1093 if mod:match("^mod_") then |
aa8647a5105d
prosodyctl check: Point out items in the modules_enabled list that incorrectly include the 'mod_' prefix
Kim Alvefur <zash@zash.se>
parents:
6958
diff
changeset
|
1094 print(""); |
aa8647a5105d
prosodyctl check: Point out items in the modules_enabled list that incorrectly include the 'mod_' prefix
Kim Alvefur <zash@zash.se>
parents:
6958
diff
changeset
|
1095 print(" Modules in modules_enabled should not have the 'mod_' prefix included."); |
aa8647a5105d
prosodyctl check: Point out items in the modules_enabled list that incorrectly include the 'mod_' prefix
Kim Alvefur <zash@zash.se>
parents:
6958
diff
changeset
|
1096 print(" Change '"..mod.."' to '"..mod:match("^mod_(.*)").."'."); |
6960
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1097 elseif mod:match("^auth_") then |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1098 print(""); |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1099 print(" Authentication modules should not be added to modules_enabled,"); |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1100 print(" but be specified in the 'authentication' option."); |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1101 print(" Remove '"..mod.."' from modules_enabled and instead add"); |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1102 print(" authentication = '"..mod:match("^auth_(.*)").."'"); |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1103 print(" For more information see https://prosody.im/doc/authentication"); |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1104 elseif mod:match("^storage_") then |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1105 print(""); |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1106 print(" storage modules should not be added to modules_enabled,"); |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1107 print(" but be specified in the 'storage' option."); |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1108 print(" Remove '"..mod.."' from modules_enabled and instead add"); |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1109 print(" storage = '"..mod:match("^storage_(.*)").."'"); |
50e2277ea05f
prosodyctl check: Point out that authentication and storage modules should not be added to modules_enabled (fixes #570)
Kim Alvefur <zash@zash.se>
parents:
6959
diff
changeset
|
1110 print(" For more information see https://prosody.im/doc/storage"); |
6959
aa8647a5105d
prosodyctl check: Point out items in the modules_enabled list that incorrectly include the 'mod_' prefix
Kim Alvefur <zash@zash.se>
parents:
6958
diff
changeset
|
1111 end |
6844
8946052e12d2
prosodyctl check: Warn if encryption is required but LuaSec is unavailable
Kim Alvefur <zash@zash.se>
parents:
6837
diff
changeset
|
1112 end |
8067
91550b6f93d2
prosodyctl: Point out how default_storage is redundant if storage is a string
Kim Alvefur <zash@zash.se>
parents:
8012
diff
changeset
|
1113 for host, config in pairs(config) do |
91550b6f93d2
prosodyctl: Point out how default_storage is redundant if storage is a string
Kim Alvefur <zash@zash.se>
parents:
8012
diff
changeset
|
1114 if type(rawget(config, "storage")) == "string" and rawget(config, "default_storage") then |
91550b6f93d2
prosodyctl: Point out how default_storage is redundant if storage is a string
Kim Alvefur <zash@zash.se>
parents:
8012
diff
changeset
|
1115 print(""); |
91550b6f93d2
prosodyctl: Point out how default_storage is redundant if storage is a string
Kim Alvefur <zash@zash.se>
parents:
8012
diff
changeset
|
1116 print(" The 'default_storage' option is not needed if 'storage' is set to a string."); |
91550b6f93d2
prosodyctl: Point out how default_storage is redundant if storage is a string
Kim Alvefur <zash@zash.se>
parents:
8012
diff
changeset
|
1117 break; |
91550b6f93d2
prosodyctl: Point out how default_storage is redundant if storage is a string
Kim Alvefur <zash@zash.se>
parents:
8012
diff
changeset
|
1118 end |
91550b6f93d2
prosodyctl: Point out how default_storage is redundant if storage is a string
Kim Alvefur <zash@zash.se>
parents:
8012
diff
changeset
|
1119 end |
7455
82d8c11ab0cb
prosodyctl: Warn if encryption is required but mod_tls is not enabled (see #617)
Kim Alvefur <zash@zash.se>
parents:
7445
diff
changeset
|
1120 local require_encryption = set.intersection(all_options, set.new({"require_encryption", "c2s_require_encryption", "s2s_require_encryption"})):empty(); |
6958
ebac87d80ef4
prosodyctl check: Really store imported LuaSec (must be a leftover from debugging)
Kim Alvefur <zash@zash.se>
parents:
6957
diff
changeset
|
1121 local ssl = dependencies.softreq"ssl"; |
6844
8946052e12d2
prosodyctl check: Warn if encryption is required but LuaSec is unavailable
Kim Alvefur <zash@zash.se>
parents:
6837
diff
changeset
|
1122 if not ssl then |
7455
82d8c11ab0cb
prosodyctl: Warn if encryption is required but mod_tls is not enabled (see #617)
Kim Alvefur <zash@zash.se>
parents:
7445
diff
changeset
|
1123 if not require_encryption then |
6844
8946052e12d2
prosodyctl check: Warn if encryption is required but LuaSec is unavailable
Kim Alvefur <zash@zash.se>
parents:
6837
diff
changeset
|
1124 print(""); |
8946052e12d2
prosodyctl check: Warn if encryption is required but LuaSec is unavailable
Kim Alvefur <zash@zash.se>
parents:
6837
diff
changeset
|
1125 print(" You require encryption but LuaSec is not available."); |
8946052e12d2
prosodyctl check: Warn if encryption is required but LuaSec is unavailable
Kim Alvefur <zash@zash.se>
parents:
6837
diff
changeset
|
1126 print(" Connections will fail."); |
8946052e12d2
prosodyctl check: Warn if encryption is required but LuaSec is unavailable
Kim Alvefur <zash@zash.se>
parents:
6837
diff
changeset
|
1127 ok = false; |
8946052e12d2
prosodyctl check: Warn if encryption is required but LuaSec is unavailable
Kim Alvefur <zash@zash.se>
parents:
6837
diff
changeset
|
1128 end |
6845
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1129 elseif not ssl.loadcertificate then |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1130 if all_options:contains("s2s_secure_auth") then |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1131 print(""); |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1132 print(" You have set s2s_secure_auth but your version of LuaSec does "); |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1133 print(" not support certificate validation, so all s2s connections will"); |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1134 print(" fail."); |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1135 ok = false; |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1136 elseif all_options:contains("s2s_secure_domains") then |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1137 local secure_domains = set.new(); |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1138 for host in enabled_hosts() do |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1139 if config[host].s2s_secure_auth == true then |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1140 secure_domains:add("*"); |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1141 else |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1142 secure_domains:include(set.new(config[host].s2s_secure_domains)); |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1143 end |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1144 end |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1145 if not secure_domains:empty() then |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1146 print(""); |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1147 print(" You have set s2s_secure_domains but your version of LuaSec does "); |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1148 print(" not support certificate validation, so s2s connections to/from "); |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1149 print(" these domains will fail."); |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1150 ok = false; |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1151 end |
bb7854355df1
prosodyctl check: Warn if certificate checking is enforced but LuaSec is too old
Kim Alvefur <zash@zash.se>
parents:
6844
diff
changeset
|
1152 end |
7455
82d8c11ab0cb
prosodyctl: Warn if encryption is required but mod_tls is not enabled (see #617)
Kim Alvefur <zash@zash.se>
parents:
7445
diff
changeset
|
1153 elseif require_encryption and not all_modules:contains("tls") then |
82d8c11ab0cb
prosodyctl: Warn if encryption is required but mod_tls is not enabled (see #617)
Kim Alvefur <zash@zash.se>
parents:
7445
diff
changeset
|
1154 print(""); |
82d8c11ab0cb
prosodyctl: Warn if encryption is required but mod_tls is not enabled (see #617)
Kim Alvefur <zash@zash.se>
parents:
7445
diff
changeset
|
1155 print(" You require encryption but mod_tls is not enabled."); |
82d8c11ab0cb
prosodyctl: Warn if encryption is required but mod_tls is not enabled (see #617)
Kim Alvefur <zash@zash.se>
parents:
7445
diff
changeset
|
1156 print(" Connections will fail."); |
82d8c11ab0cb
prosodyctl: Warn if encryption is required but mod_tls is not enabled (see #617)
Kim Alvefur <zash@zash.se>
parents:
7445
diff
changeset
|
1157 ok = false; |
6844
8946052e12d2
prosodyctl check: Warn if encryption is required but LuaSec is unavailable
Kim Alvefur <zash@zash.se>
parents:
6837
diff
changeset
|
1158 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1159 |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1160 print("Done.\n"); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1161 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1162 if not what or what == "dns" then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1163 local dns = require "net.dns"; |
5809
be997c6a69be
prosodyctl: check: Support for unicode (IDN) domains (thanks once again albert)
Matthew Wild <mwild1@gmail.com>
parents:
5723
diff
changeset
|
1164 local idna = require "util.encodings".idna; |
5592
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1165 local ip = require "util.ip"; |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1166 local c2s_ports = set.new(config.get("*", "c2s_ports") or {5222}); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1167 local s2s_ports = set.new(config.get("*", "s2s_ports") or {5269}); |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1168 |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1169 local c2s_srv_required, s2s_srv_required; |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1170 if not c2s_ports:contains(5222) then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1171 c2s_srv_required = true; |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1172 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1173 if not s2s_ports:contains(5269) then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1174 s2s_srv_required = true; |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1175 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1176 |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1177 local problem_hosts = set.new(); |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1178 |
5592
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1179 local external_addresses, internal_addresses = set.new(), set.new(); |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1180 |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1181 local fqdn = socket.dns.tohostname(socket.dns.gethostname()); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1182 if fqdn then |
5809
be997c6a69be
prosodyctl: check: Support for unicode (IDN) domains (thanks once again albert)
Matthew Wild <mwild1@gmail.com>
parents:
5723
diff
changeset
|
1183 local res = dns.lookup(idna.to_ascii(fqdn), "A"); |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1184 if res then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1185 for _, record in ipairs(res) do |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1186 external_addresses:add(record.a); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1187 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1188 end |
5809
be997c6a69be
prosodyctl: check: Support for unicode (IDN) domains (thanks once again albert)
Matthew Wild <mwild1@gmail.com>
parents:
5723
diff
changeset
|
1189 local res = dns.lookup(idna.to_ascii(fqdn), "AAAA"); |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1190 if res then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1191 for _, record in ipairs(res) do |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1192 external_addresses:add(record.aaaa); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1193 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1194 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1195 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1196 |
5723
24b6eb65480c
prosodyctl: Import local_addresses from the new util.net intead of luasocket
Kim Alvefur <zash@zash.se>
parents:
5657
diff
changeset
|
1197 local local_addresses = require"util.net".local_addresses() or {}; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1198 |
5592
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1199 for addr in it.values(local_addresses) do |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1200 if not ip.new_ip(addr).private then |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1201 external_addresses:add(addr); |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1202 else |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1203 internal_addresses:add(addr); |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1204 end |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1205 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1206 |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1207 if external_addresses:empty() then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1208 print(""); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1209 print(" Failed to determine the external addresses of this server. Checks may be inaccurate."); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1210 c2s_srv_required, s2s_srv_required = true, true; |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1211 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1212 |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1213 local v6_supported = not not socket.tcp6; |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1214 |
7311
e9526dd3e8fc
prosodyctl: Only use host part of JIDs eg components that have node parts (thanks suzyo)
Kim Alvefur <zash@zash.se>
parents:
7297
diff
changeset
|
1215 for jid, host_options in enabled_hosts() do |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1216 local all_targets_ok, some_targets_ok = true, false; |
7311
e9526dd3e8fc
prosodyctl: Only use host part of JIDs eg components that have node parts (thanks suzyo)
Kim Alvefur <zash@zash.se>
parents:
7297
diff
changeset
|
1217 local node, host = jid_split(jid); |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1218 |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1219 local is_component = not not host_options.component_module; |
7311
e9526dd3e8fc
prosodyctl: Only use host part of JIDs eg components that have node parts (thanks suzyo)
Kim Alvefur <zash@zash.se>
parents:
7297
diff
changeset
|
1220 print("Checking DNS for "..(is_component and "component" or "host").." "..jid.."..."); |
e9526dd3e8fc
prosodyctl: Only use host part of JIDs eg components that have node parts (thanks suzyo)
Kim Alvefur <zash@zash.se>
parents:
7297
diff
changeset
|
1221 if node then |
e9526dd3e8fc
prosodyctl: Only use host part of JIDs eg components that have node parts (thanks suzyo)
Kim Alvefur <zash@zash.se>
parents:
7297
diff
changeset
|
1222 print("Only the domain part ("..host..") is used in DNS.") |
e9526dd3e8fc
prosodyctl: Only use host part of JIDs eg components that have node parts (thanks suzyo)
Kim Alvefur <zash@zash.se>
parents:
7297
diff
changeset
|
1223 end |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1224 local target_hosts = set.new(); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1225 if not is_component then |
5809
be997c6a69be
prosodyctl: check: Support for unicode (IDN) domains (thanks once again albert)
Matthew Wild <mwild1@gmail.com>
parents:
5723
diff
changeset
|
1226 local res = dns.lookup("_xmpp-client._tcp."..idna.to_ascii(host)..".", "SRV"); |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1227 if res then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1228 for _, record in ipairs(res) do |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1229 target_hosts:add(record.srv.target); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1230 if not c2s_ports:contains(record.srv.port) then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1231 print(" SRV target "..record.srv.target.." contains unknown client port: "..record.srv.port); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1232 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1233 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1234 else |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1235 if c2s_srv_required then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1236 print(" No _xmpp-client SRV record found for "..host..", but it looks like you need one."); |
7252
fa0169cc8511
prosodyctl: Fix typo'd variable name [luacheck]
Matthew Wild <mwild1@gmail.com>
parents:
7250
diff
changeset
|
1237 all_targets_ok = false; |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1238 else |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1239 target_hosts:add(host); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1240 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1241 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1242 end |
5809
be997c6a69be
prosodyctl: check: Support for unicode (IDN) domains (thanks once again albert)
Matthew Wild <mwild1@gmail.com>
parents:
5723
diff
changeset
|
1243 local res = dns.lookup("_xmpp-server._tcp."..idna.to_ascii(host)..".", "SRV"); |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1244 if res then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1245 for _, record in ipairs(res) do |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1246 target_hosts:add(record.srv.target); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1247 if not s2s_ports:contains(record.srv.port) then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1248 print(" SRV target "..record.srv.target.." contains unknown server port: "..record.srv.port); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1249 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1250 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1251 else |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1252 if s2s_srv_required then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1253 print(" No _xmpp-server SRV record found for "..host..", but it looks like you need one."); |
5589
8745193e651e
prosodyctl: check dns: Correctly mark host as failed if expected SRV records are not found
Matthew Wild <mwild1@gmail.com>
parents:
5585
diff
changeset
|
1254 all_targets_ok = false; |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1255 else |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1256 target_hosts:add(host); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1257 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1258 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1259 if target_hosts:empty() then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1260 target_hosts:add(host); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1261 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1262 |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1263 if target_hosts:contains("localhost") then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1264 print(" Target 'localhost' cannot be accessed from other servers"); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1265 target_hosts:remove("localhost"); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1266 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1267 |
7080
6946c3d5645f
prosodyctl check: Fix traceback if the global modules_enabled is unset
Kim Alvefur <zash@zash.se>
parents:
7065
diff
changeset
|
1268 local modules = set.new(it.to_array(it.values(host_options.modules_enabled or {}))) |
6946c3d5645f
prosodyctl check: Fix traceback if the global modules_enabled is unset
Kim Alvefur <zash@zash.se>
parents:
7065
diff
changeset
|
1269 + set.new(it.to_array(it.values(config.get("*", "modules_enabled") or {}))) |
5620
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1270 + set.new({ config.get(host, "component_module") }); |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1271 |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1272 if modules:contains("proxy65") then |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1273 local proxy65_target = config.get(host, "proxy65_address") or host; |
5809
be997c6a69be
prosodyctl: check: Support for unicode (IDN) domains (thanks once again albert)
Matthew Wild <mwild1@gmail.com>
parents:
5723
diff
changeset
|
1274 local A, AAAA = dns.lookup(idna.to_ascii(proxy65_target), "A"), dns.lookup(idna.to_ascii(proxy65_target), "AAAA"); |
5620
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1275 local prob = {}; |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1276 if not A then |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1277 table.insert(prob, "A"); |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1278 end |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1279 if v6_supported and not AAAA then |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1280 table.insert(prob, "AAAA"); |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1281 end |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1282 if #prob > 0 then |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1283 print(" File transfer proxy "..proxy65_target.." has no "..table.concat(prob, "/").." record. Create one or set 'proxy65_address' to the correct host/IP."); |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1284 end |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
1285 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1286 |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1287 for host in target_hosts do |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1288 local host_ok_v4, host_ok_v6; |
5809
be997c6a69be
prosodyctl: check: Support for unicode (IDN) domains (thanks once again albert)
Matthew Wild <mwild1@gmail.com>
parents:
5723
diff
changeset
|
1289 local res = dns.lookup(idna.to_ascii(host), "A"); |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1290 if res then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1291 for _, record in ipairs(res) do |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1292 if external_addresses:contains(record.a) then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1293 some_targets_ok = true; |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1294 host_ok_v4 = true; |
5592
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1295 elseif internal_addresses:contains(record.a) then |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1296 host_ok_v4 = true; |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1297 some_targets_ok = true; |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1298 print(" "..host.." A record points to internal address, external connections might fail"); |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1299 else |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1300 print(" "..host.." A record points to unknown address "..record.a); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1301 all_targets_ok = false; |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1302 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1303 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1304 end |
5809
be997c6a69be
prosodyctl: check: Support for unicode (IDN) domains (thanks once again albert)
Matthew Wild <mwild1@gmail.com>
parents:
5723
diff
changeset
|
1305 local res = dns.lookup(idna.to_ascii(host), "AAAA"); |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1306 if res then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1307 for _, record in ipairs(res) do |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1308 if external_addresses:contains(record.aaaa) then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1309 some_targets_ok = true; |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1310 host_ok_v6 = true; |
5592
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1311 elseif internal_addresses:contains(record.aaaa) then |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1312 host_ok_v6 = true; |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1313 some_targets_ok = true; |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
1314 print(" "..host.." AAAA record points to internal address, external connections might fail"); |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1315 else |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1316 print(" "..host.." AAAA record points to unknown address "..record.aaaa); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1317 all_targets_ok = false; |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1318 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1319 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1320 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1321 |
5590
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1322 local bad_protos = {} |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1323 if not host_ok_v4 then |
5590
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1324 table.insert(bad_protos, "IPv4"); |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1325 end |
5590
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1326 if not host_ok_v6 then |
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1327 table.insert(bad_protos, "IPv6"); |
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1328 end |
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1329 if #bad_protos > 0 then |
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1330 print(" Host "..host.." does not seem to resolve to this server ("..table.concat(bad_protos, "/")..")"); |
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1331 end |
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1332 if host_ok_v6 and not v6_supported then |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1333 print(" Host "..host.." has AAAA records, but your version of LuaSocket does not support IPv6."); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1334 print(" Please see http://prosody.im/doc/ipv6 for more information."); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1335 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1336 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1337 if not all_targets_ok then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1338 print(" "..(some_targets_ok and "Only some" or "No").." targets for "..host.." appear to resolve to this server."); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1339 if is_component then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1340 print(" DNS records are necessary if you want users on other servers to access this component."); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1341 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1342 problem_hosts:add(host); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1343 end |
5591
f0bf2a1790d9
prosodyctl: check dns: Whitespace fix in output
Matthew Wild <mwild1@gmail.com>
parents:
5590
diff
changeset
|
1344 print(""); |
5585
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1345 end |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1346 if not problem_hosts:empty() then |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1347 print(""); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1348 print("For more information about DNS configuration please see http://prosody.im/doc/dns"); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1349 print(""); |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1350 ok = false; |
3e097acf82de
prosodyctl: Add 'prosodyctl check dns' to make an attempt at verifying the server's DNS records
Matthew Wild <mwild1@gmail.com>
parents:
5584
diff
changeset
|
1351 end |
5584
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1352 end |
5657
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1353 if not what or what == "certs" then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1354 local cert_ok; |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1355 print"Checking certificates..." |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1356 local x509_verify_identity = require"util.x509".verify_identity; |
7208
f666d50cc32b
prosodyctl: check certs: Use certmanager to get the final ssl config in order to support the new certificate(s) config option
Kim Alvefur <zash@zash.se>
parents:
7193
diff
changeset
|
1357 local create_context = require "core.certmanager".create_context; |
5657
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1358 local ssl = dependencies.softreq"ssl"; |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1359 -- local datetime_parse = require"util.datetime".parse_x509; |
6612
6cc48b51d699
prosodyctl: Use ssl.loadcertificate instead of ssl.x509.load, as the ssl.x509 export dissapears in 97b1974 or 356e03a
Kim Alvefur <zash@zash.se>
parents:
6611
diff
changeset
|
1360 local load_cert = ssl and ssl.loadcertificate; |
5657
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1361 -- or ssl.cert_from_pem |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1362 if not ssl then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1363 print("LuaSec not available, can't perform certificate checks") |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1364 if what == "certs" then cert_ok = false end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1365 elseif not load_cert then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1366 print("This version of LuaSec (" .. ssl._VERSION .. ") does not support certificate checking"); |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1367 cert_ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1368 else |
8190
331caee0c774
prosodyctl: Skip certificate checks for hosts of the form node@host (fixes #779)
Kim Alvefur <zash@zash.se>
parents:
8177
diff
changeset
|
1369 local function skip_bare_jid_hosts(host) |
331caee0c774
prosodyctl: Skip certificate checks for hosts of the form node@host (fixes #779)
Kim Alvefur <zash@zash.se>
parents:
8177
diff
changeset
|
1370 if jid_split(host) then |
331caee0c774
prosodyctl: Skip certificate checks for hosts of the form node@host (fixes #779)
Kim Alvefur <zash@zash.se>
parents:
8177
diff
changeset
|
1371 -- See issue #779 |
331caee0c774
prosodyctl: Skip certificate checks for hosts of the form node@host (fixes #779)
Kim Alvefur <zash@zash.se>
parents:
8177
diff
changeset
|
1372 return false; |
331caee0c774
prosodyctl: Skip certificate checks for hosts of the form node@host (fixes #779)
Kim Alvefur <zash@zash.se>
parents:
8177
diff
changeset
|
1373 end |
331caee0c774
prosodyctl: Skip certificate checks for hosts of the form node@host (fixes #779)
Kim Alvefur <zash@zash.se>
parents:
8177
diff
changeset
|
1374 return true; |
331caee0c774
prosodyctl: Skip certificate checks for hosts of the form node@host (fixes #779)
Kim Alvefur <zash@zash.se>
parents:
8177
diff
changeset
|
1375 end |
331caee0c774
prosodyctl: Skip certificate checks for hosts of the form node@host (fixes #779)
Kim Alvefur <zash@zash.se>
parents:
8177
diff
changeset
|
1376 for host in it.filter(skip_bare_jid_hosts, enabled_hosts()) do |
6158
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1377 print("Checking certificate for "..host); |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1378 -- First, let's find out what certificate this host uses. |
7208
f666d50cc32b
prosodyctl: check certs: Use certmanager to get the final ssl config in order to support the new certificate(s) config option
Kim Alvefur <zash@zash.se>
parents:
7193
diff
changeset
|
1379 local host_ssl_config = config.rawget(host, "ssl") |
f666d50cc32b
prosodyctl: check certs: Use certmanager to get the final ssl config in order to support the new certificate(s) config option
Kim Alvefur <zash@zash.se>
parents:
7193
diff
changeset
|
1380 or config.rawget(host:match("%.(.*)"), "ssl"); |
f666d50cc32b
prosodyctl: check certs: Use certmanager to get the final ssl config in order to support the new certificate(s) config option
Kim Alvefur <zash@zash.se>
parents:
7193
diff
changeset
|
1381 local global_ssl_config = config.rawget("*", "ssl"); |
f666d50cc32b
prosodyctl: check certs: Use certmanager to get the final ssl config in order to support the new certificate(s) config option
Kim Alvefur <zash@zash.se>
parents:
7193
diff
changeset
|
1382 local ok, err, ssl_config = create_context(host, "server", host_ssl_config, global_ssl_config); |
f666d50cc32b
prosodyctl: check certs: Use certmanager to get the final ssl config in order to support the new certificate(s) config option
Kim Alvefur <zash@zash.se>
parents:
7193
diff
changeset
|
1383 if not ok then |
f666d50cc32b
prosodyctl: check certs: Use certmanager to get the final ssl config in order to support the new certificate(s) config option
Kim Alvefur <zash@zash.se>
parents:
7193
diff
changeset
|
1384 print(" Error: "..err); |
6158
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1385 cert_ok = false |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1386 elseif not ssl_config.certificate then |
7209
92e5036bc55c
prosodyctl: check certs: Update messages to account for 'ssl' option maybe not existing
Kim Alvefur <zash@zash.se>
parents:
7208
diff
changeset
|
1387 print(" No 'certificate' found for "..host) |
6158
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1388 cert_ok = false |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1389 elseif not ssl_config.key then |
7212
167dbd29fbeb
prosodyctl: Fix typo (thanks av6)
Kim Alvefur <zash@zash.se>
parents:
7210
diff
changeset
|
1390 print(" No 'key' found for "..host) |
6158
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1391 cert_ok = false |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1392 else |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1393 local key, err = io.open(ssl_config.key); -- Permissions check only |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1394 if not key then |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1395 print(" Could not open "..ssl_config.key..": "..err); |
5657
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1396 cert_ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1397 else |
6158
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1398 key:close(); |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1399 end |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1400 local cert_fh, err = io.open(ssl_config.certificate); -- Load the file. |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1401 if not cert_fh then |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1402 print(" Could not open "..ssl_config.certificate..": "..err); |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1403 cert_ok = false |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1404 else |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1405 print(" Certificate: "..ssl_config.certificate) |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1406 local cert = load_cert(cert_fh:read"*a"); cert_fh = cert_fh:close(); |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1407 if not cert:validat(os.time()) then |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1408 print(" Certificate has expired.") |
5657
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1409 cert_ok = false |
7210
48149ecbb649
prosodyctl: check certs: Warn about certificate expiry in the near future
Kim Alvefur <zash@zash.se>
parents:
7209
diff
changeset
|
1410 elseif not cert:validat(os.time() + 86400) then |
48149ecbb649
prosodyctl: check certs: Warn about certificate expiry in the near future
Kim Alvefur <zash@zash.se>
parents:
7209
diff
changeset
|
1411 print(" Certificate expires within one day.") |
48149ecbb649
prosodyctl: check certs: Warn about certificate expiry in the near future
Kim Alvefur <zash@zash.se>
parents:
7209
diff
changeset
|
1412 cert_ok = false |
48149ecbb649
prosodyctl: check certs: Warn about certificate expiry in the near future
Kim Alvefur <zash@zash.se>
parents:
7209
diff
changeset
|
1413 elseif not cert:validat(os.time() + 86400*7) then |
48149ecbb649
prosodyctl: check certs: Warn about certificate expiry in the near future
Kim Alvefur <zash@zash.se>
parents:
7209
diff
changeset
|
1414 print(" Certificate expires within one week.") |
7213
193e4c65d218
prosodyctl: One month is 31 days, no 13 (thanks av6)
Kim Alvefur <zash@zash.se>
parents:
7212
diff
changeset
|
1415 elseif not cert:validat(os.time() + 86400*31) then |
7210
48149ecbb649
prosodyctl: check certs: Warn about certificate expiry in the near future
Kim Alvefur <zash@zash.se>
parents:
7209
diff
changeset
|
1416 print(" Certificate expires within one month.") |
6158
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1417 end |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1418 if config.get(host, "component_module") == nil |
5657
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1419 and not x509_verify_identity(host, "_xmpp-client", cert) then |
7445
6d2038147d3d
prosodyctl: Fix typo (thanks av6)
Kim Alvefur <zash@zash.se>
parents:
7311
diff
changeset
|
1420 print(" Not valid for client connections to "..host..".") |
6158
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1421 cert_ok = false |
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1422 end |
6161
afcba9737ac3
prosodyctl: Use correct variable in check certs
Kim Alvefur <zash@zash.se>
parents:
6160
diff
changeset
|
1423 if (not (config.get(host, "anonymous_login") |
afcba9737ac3
prosodyctl: Use correct variable in check certs
Kim Alvefur <zash@zash.se>
parents:
6160
diff
changeset
|
1424 or config.get(host, "authentication") == "anonymous")) |
6637
ecc039288edc
prosodyctl: check certs: Correctly check that certificates are valid for s2s
Kim Alvefur <zash@zash.se>
parents:
6612
diff
changeset
|
1425 and not x509_verify_identity(host, "_xmpp-server", cert) then |
7445
6d2038147d3d
prosodyctl: Fix typo (thanks av6)
Kim Alvefur <zash@zash.se>
parents:
7311
diff
changeset
|
1426 print(" Not valid for server-to-server connections to "..host..".") |
6158
08e9c9d0beb3
prosodyctl: Only perform checks on enabled hosts
Kim Alvefur <zash@zash.se>
parents:
6062
diff
changeset
|
1427 cert_ok = false |
5657
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1428 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1429 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1430 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1431 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1432 if cert_ok == false then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1433 print("") |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1434 print("For more information about certificates please see http://prosody.im/doc/certificates"); |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1435 ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1436 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1437 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1438 print("") |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1439 end |
5584
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1440 if not ok then |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1441 print("Problems found, see above."); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1442 else |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1443 print("All checks passed, congratulations!"); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1444 end |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1445 return ok and 0 or 2; |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1446 end |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
1447 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1448 --------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1449 |
1499
51e3e22b5316
prosodyctl: Fix traceback when issued with no parameters
Matthew Wild <mwild1@gmail.com>
parents:
1460
diff
changeset
|
1450 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
|
1451 local module_name = command:match("^mod_(.+)"); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1452 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
|
1453 if not ret then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1454 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
|
1455 os.exit(1); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1456 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1457 |
1390
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1458 table.remove(arg, 1); |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1459 |
1390
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1460 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
|
1461 if not module then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1462 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
|
1463 os.exit(1); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1464 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1465 |
1390
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1466 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
|
1467 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
|
1468 os.exit(1); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1469 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1470 |
1390
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1471 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
|
1472 if ok then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1473 if type(ret) == "number" then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1474 os.exit(ret); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1475 elseif type(ret) == "string" then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1476 show_message(ret); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1477 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1478 os.exit(0); -- :) |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1479 else |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1480 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
|
1481 os.exit(1); -- :( |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1482 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1483 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1484 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1485 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
|
1486 function show_usage(usage, desc) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1487 print(" "..usage); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1488 print(" "..desc); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1489 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1490 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1491 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
|
1492 print(""); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1493 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
|
1494 print(""); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1495 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
|
1496 |
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
|
1497 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
|
1498 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
|
1499 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1500 local done = {}; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1501 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1502 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
|
1503 local command = commands[command_name]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1504 if command then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1505 command{ "--help" }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1506 print"" |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1507 done[command_name] = true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1508 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1509 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1510 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1511 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
|
1512 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
|
1513 command{ "--help" }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1514 print"" |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1515 done[command_name] = true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1516 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1517 end |
7922
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1518 |
2fd20f372cb1
prosodyctl: Trim trailing whitespace
Kim Alvefur <zash@zash.se>
parents:
7920
diff
changeset
|
1519 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1520 os.exit(0); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1521 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1522 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1523 os.exit(commands[command]({ select(2, unpack(arg)) })); |