Software /
code /
prosody
Annotate
prosodyctl @ 6057:a3d7b8f4d9c7
mod_compression: Use get_child() and get_child_text()
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Thu, 03 Apr 2014 23:40:20 +0200 |
parent | 6038:b3ceb7627e27 |
child | 6062:6cc6b4d407df |
rev | line source |
---|---|
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env lua |
1523
841d61be198f
Remove version number from copyright headers
Matthew Wild <mwild1@gmail.com>
parents:
1501
diff
changeset
|
2 -- Prosody IM |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
3 -- Copyright (C) 2008-2010 Matthew Wild |
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
4 -- Copyright (C) 2008-2010 Waqas Hussain |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
5 -- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
6 -- This project is MIT/X11 licensed. Please see the |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
7 -- COPYING file in the source package for more information. |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
8 -- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
9 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
10 -- prosodyctl - command-line controller for Prosody XMPP server |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
11 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
12 -- Will be modified by configure script if run -- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
13 |
3741
f7dd583d99b4
prosodyctl: Read PROSODY_SRCDIR and PROSODY_PLUGINDIR environment variables, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3739
diff
changeset
|
14 CFG_SOURCEDIR=os.getenv("PROSODY_SRCDIR"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
15 CFG_CONFIGDIR=os.getenv("PROSODY_CFGDIR"); |
3741
f7dd583d99b4
prosodyctl: Read PROSODY_SRCDIR and PROSODY_PLUGINDIR environment variables, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3739
diff
changeset
|
16 CFG_PLUGINDIR=os.getenv("PROSODY_PLUGINDIR"); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
17 CFG_DATADIR=os.getenv("PROSODY_DATADIR"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
18 |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
19 -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
20 |
3999
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
21 local function is_relative(path) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
22 local path_sep = package.config:sub(1,1); |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
23 return ((path_sep == "/" and path:sub(1,1) ~= "/") |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
24 or (path_sep == "\\" and (path:sub(1,1) ~= "/" and path:sub(2,3) ~= ":\\"))) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
25 end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
26 |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
27 -- Tell Lua where to find our libraries |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
28 if CFG_SOURCEDIR then |
3999
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
29 local function filter_relative_paths(path) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
30 if is_relative(path) then return ""; end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
31 end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
32 local function sanitise_paths(paths) |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
33 return (paths:gsub("[^;]+;?", filter_relative_paths):gsub(";;+", ";")); |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
34 end |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
35 package.path = sanitise_paths(CFG_SOURCEDIR.."/?.lua;"..package.path); |
58c0de7c6da0
prosody, prosodyctl: Filter out relative paths from package.(c)path when installed
Matthew Wild <mwild1@gmail.com>
parents:
3998
diff
changeset
|
36 package.cpath = sanitise_paths(CFG_SOURCEDIR.."/?.so;"..package.cpath); |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
37 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
38 |
3742
a18acd47904b
prosodyctl: Added and updated some comments and some semicolons, to match main prosody executable.
Waqas Hussain <waqas20@gmail.com>
parents:
3741
diff
changeset
|
39 -- Substitute ~ with path to home directory in data path |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
40 if CFG_DATADIR then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
41 if os.getenv("HOME") then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
42 CFG_DATADIR = CFG_DATADIR:gsub("^~", os.getenv("HOME")); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
43 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
44 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
45 |
3013
518e3f6f9946
prosodyctl: Relocate global prosody object creation (see fff153f7f4de)
Matthew Wild <mwild1@gmail.com>
parents:
2706
diff
changeset
|
46 -- Global 'prosody' object |
3998
009d1ad84b49
prosody, prosodyctl: Create prosody object as a local before exporting as a global
Matthew Wild <mwild1@gmail.com>
parents:
3904
diff
changeset
|
47 local prosody = { |
3773
2e15808243f3
prosodyctl: Add dummy lock/unlock_globals() until util.startup comes along
Matthew Wild <mwild1@gmail.com>
parents:
3742
diff
changeset
|
48 hosts = {}; |
2e15808243f3
prosodyctl: Add dummy lock/unlock_globals() until util.startup comes along
Matthew Wild <mwild1@gmail.com>
parents:
3742
diff
changeset
|
49 events = require "util.events".new(); |
2e15808243f3
prosodyctl: Add dummy lock/unlock_globals() until util.startup comes along
Matthew Wild <mwild1@gmail.com>
parents:
3742
diff
changeset
|
50 platform = "posix"; |
2e15808243f3
prosodyctl: Add dummy lock/unlock_globals() until util.startup comes along
Matthew Wild <mwild1@gmail.com>
parents:
3742
diff
changeset
|
51 lock_globals = function () end; |
2e15808243f3
prosodyctl: Add dummy lock/unlock_globals() until util.startup comes along
Matthew Wild <mwild1@gmail.com>
parents:
3742
diff
changeset
|
52 unlock_globals = function () end; |
5134
43c5227fdd3b
prosody, prosodyctl: chdir() to data directory on startup
Matthew Wild <mwild1@gmail.com>
parents:
5101
diff
changeset
|
53 installed = CFG_SOURCEDIR ~= nil; |
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 = {}; |
9ee223177319
prosodyctl: Added support for --config command line argument, and multiple config parsers (to match the main prosody executable).
Waqas Hussain <waqas20@gmail.com>
parents:
3724
diff
changeset
|
68 |
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 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
96 print("A problem occured while reading the config file "..(CFG_CONFIGDIR or ".").."/prosody.cfg.lua"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
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."); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
102 print("We looked for: "..(CFG_CONFIGDIR or ".").."/prosody.cfg.lua"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
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 |
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
|
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 |
5456
87204440b9dd
prosodyctl: Bump util.pposix version for API change
Kim Alvefur <zash@zash.se>
parents:
5438
diff
changeset
|
138 local want_pposix_version = "0.3.6"; |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
139 local ok, pposix = pcall(require, "util.pposix"); |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
140 |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
141 if ok and pposix then |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
142 if pposix._VERSION ~= want_pposix_version then print(string.format("Unknown version (%s) of binary pposix module, expected %s", tostring(pposix._VERSION), want_pposix_version)); return; end |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
143 current_uid = pposix.getuid(); |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
144 if current_uid == 0 then |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
145 -- We haz root! |
5384
24f4aed5824f
prosody, prosodyctl: Remove last trace of "core" \o/
Kim Alvefur <zash@zash.se>
parents:
5296
diff
changeset
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 if ok then |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
153 ok, err = pposix.setuid(desired_user); |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
154 if ok then |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
155 -- Yay! |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
156 switched_user = true; |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
157 end |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
158 end |
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
159 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
|
160 -- Boo! |
1580
5be6dc582df3
prosodyctl: Also switch group when we switch user
Matthew Wild <mwild1@gmail.com>
parents:
1523
diff
changeset
|
161 print("Warning: Couldn't switch to Prosody user/group '"..tostring(desired_user).."'/'"..tostring(desired_group).."': "..tostring(err)); |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
162 end |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
163 end |
2439
511ba389147a
prosodyctl: Set umask to protect data files, bump pposix dep to 0.3.2
Matthew Wild <mwild1@gmail.com>
parents:
2410
diff
changeset
|
164 |
511ba389147a
prosodyctl: Set umask to protect data files, bump pposix dep to 0.3.2
Matthew Wild <mwild1@gmail.com>
parents:
2410
diff
changeset
|
165 -- 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
|
166 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
|
167 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
|
168 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
|
169 else |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
170 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
|
171 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
|
172 print(tostring(pposix)) |
5150
81b49bb0ecc7
prosodyctl: Abort if unable to load util.pposix
Kim Alvefur <zash@zash.se>
parents:
5149
diff
changeset
|
173 os.exit(1); |
1114
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
174 end |
c463e30da312
prosodyctl: Switch to Prosody user before attempting to do anything
Matthew Wild <mwild1@gmail.com>
parents:
1102
diff
changeset
|
175 |
3339
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
176 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
|
177 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
|
178 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
|
179 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
|
180 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
181 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
|
182 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
|
183 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
184 |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
185 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
|
186 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
|
187 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
|
188 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
|
189 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
|
190 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
191 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
|
192 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
|
193 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
|
194 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
|
195 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
|
196 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
|
197 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
198 end |
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 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
201 |
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 #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
|
203 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
|
204 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
|
205 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
|
206 print(""); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
207 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
|
208 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
|
209 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
210 print(""); |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
211 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
|
212 end |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
213 |
7893055e54d1
prosodyctl: Warn and exit if any log files are not writeable, fixes #94
Matthew Wild <mwild1@gmail.com>
parents:
3338
diff
changeset
|
214 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
215 local error_messages = setmetatable({ |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
216 ["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
|
217 ["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
|
218 ["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
|
219 ["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
|
220 ["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
|
221 ["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
|
222 ["no-pidfile"] = "There is no 'pidfile' option in the configuration file, see http://prosody.im/doc/prosodyctl#pidfile for help"; |
3627
9e62937c9757
prosodyctl, util.prosodyctl: Show error when mod_posix is not enabled and an attempt is made to query Prosody's status (thanks stever)
Matthew Wild <mwild1@gmail.com>
parents:
3481
diff
changeset
|
223 ["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
|
224 ["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
|
225 ["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
|
226 }, { __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
|
227 |
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
|
228 hosts = prosody.hosts; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
229 |
3038
6b68355d615a
prosodyctl: Support for the new usermanager, refactor host creation and fail if a host is not using the default authentication provider, for now. (thanks Nicola)
Matthew Wild <mwild1@gmail.com>
parents:
3015
diff
changeset
|
230 local function make_host(hostname) |
3630
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
231 return { |
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
232 type = "local", |
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
233 events = prosody.events, |
5142
3221746f4769
prosodyctl: Make sure hosts[*].modules always exists.
Waqas Hussain <waqas20@gmail.com>
parents:
5134
diff
changeset
|
234 modules = {}, |
3630
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
235 users = require "core.usermanager".new_null_provider(hostname) |
e0c67b14d25f
prosodyctl: Give hosts type = 'local'
Matthew Wild <mwild1@gmail.com>
parents:
3627
diff
changeset
|
236 }; |
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
|
237 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
|
238 |
2020
24f54340a670
prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents:
1580
diff
changeset
|
239 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
|
240 hosts[hostname] = make_host(hostname); |
2020
24f54340a670
prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents:
1580
diff
changeset
|
241 end |
24f54340a670
prosodyctl: Remove dependency on hostmanager, and friends
Matthew Wild <mwild1@gmail.com>
parents:
1580
diff
changeset
|
242 |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4881
diff
changeset
|
243 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
|
244 |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4881
diff
changeset
|
245 local prosodyctl = require "util.prosodyctl" |
1458
fce75b4efda9
prosodyctl: Improve usability with status messages, and waiting up to 5s for the server to start/stop
Matthew Wild <mwild1@gmail.com>
parents:
1390
diff
changeset
|
246 require "socket" |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
247 ----------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
248 |
4881
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
249 -- FIXME: Duplicate code waiting for util.startup |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
250 function read_version() |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
251 -- Try to determine version |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
252 local version_file = io.open((CFG_SOURCEDIR or ".").."/prosody.version"); |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
253 if version_file then |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
254 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
|
255 version_file:close(); |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
256 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
|
257 prosody.version = "hg:"..prosody.version; |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
258 end |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
259 else |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
260 prosody.version = "unknown"; |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
261 end |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
262 end |
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
263 |
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
|
264 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
|
265 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
|
266 local getchar, getpass = prosodyctl.getchar, prosodyctl.getpass; |
caa78589598f
prosodyctl, util.prosodyctl: Move UI functions to util.prosodyctl so they can be used outside of prosodyctl itself
Matthew Wild <mwild1@gmail.com>
parents:
4095
diff
changeset
|
267 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
|
268 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
|
269 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
|
270 |
5384
24f4aed5824f
prosody, prosodyctl: Remove last trace of "core" \o/
Kim Alvefur <zash@zash.se>
parents:
5296
diff
changeset
|
271 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
|
272 ----------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
273 local commands = {}; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
274 local command = arg[1]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
275 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
276 function commands.adduser(arg) |
5610
f73d5fb4ea13
prosodyctl: Use jid.split() to parse parameter to adduser/deluser/passwd
Matthew Wild <mwild1@gmail.com>
parents:
5592
diff
changeset
|
277 local jid_split = require "util.jid".split; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
278 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
|
279 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
|
280 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
281 end |
5610
f73d5fb4ea13
prosodyctl: Use jid.split() to parse parameter to adduser/deluser/passwd
Matthew Wild <mwild1@gmail.com>
parents:
5592
diff
changeset
|
282 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
|
283 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
|
284 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
|
285 show_usage [[adduser user@host]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
286 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
287 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
288 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
289 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
290 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
|
291 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
292 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
293 |
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
|
294 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
|
295 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
|
296 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
|
297 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
|
298 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
|
299 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
300 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
|
301 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
|
302 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
303 end |
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 local password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
306 if not password then return 1; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
307 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
308 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
309 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
310 if ok then return 0; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
311 |
3777
5ecbcef42ffb
mod_admin_adhoc: Support for reloading multiple modules
Florian Zeitz <florob@babelmonkeys.de>
parents:
3773
diff
changeset
|
312 show_message(msg) |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
313 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
314 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
315 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
316 function commands.passwd(arg) |
5610
f73d5fb4ea13
prosodyctl: Use jid.split() to parse parameter to adduser/deluser/passwd
Matthew Wild <mwild1@gmail.com>
parents:
5592
diff
changeset
|
317 local jid_split = require "util.jid".split; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
318 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
|
319 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
|
320 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
321 end |
5610
f73d5fb4ea13
prosodyctl: Use jid.split() to parse parameter to adduser/deluser/passwd
Matthew Wild <mwild1@gmail.com>
parents:
5592
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 show_usage [[passwd user@host]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
326 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
327 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
328 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
329 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
330 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
|
331 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
332 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
333 |
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
|
334 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
|
335 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
|
336 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
|
337 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
|
338 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
|
339 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
340 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
|
341 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
|
342 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
343 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
344 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
345 local password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
346 if not password then return 1; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
347 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
348 local ok, msg = prosodyctl.passwd { user = user, host = host, password = password }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
349 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
350 if ok then return 0; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
351 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
352 show_message(error_messages[msg]) |
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 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
355 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
356 function commands.deluser(arg) |
5610
f73d5fb4ea13
prosodyctl: Use jid.split() to parse parameter to adduser/deluser/passwd
Matthew Wild <mwild1@gmail.com>
parents:
5592
diff
changeset
|
357 local jid_split = require "util.jid".split; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
358 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
|
359 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
|
360 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
361 end |
5610
f73d5fb4ea13
prosodyctl: Use jid.split() to parse parameter to adduser/deluser/passwd
Matthew Wild <mwild1@gmail.com>
parents:
5592
diff
changeset
|
362 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
|
363 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
|
364 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
|
365 show_usage [[passwd user@host]] |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
366 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
367 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
368 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
369 if not host then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
370 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
|
371 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
372 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
373 |
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
|
374 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
|
375 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
|
376 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
|
377 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
|
378 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
|
379 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
380 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
|
381 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
|
382 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
383 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
384 |
5101
a94c43cad081
prosodyctl: Use util.prosodyctl.deluser
Kim Alvefur <zash@zash.se>
parents:
5024
diff
changeset
|
385 local ok, msg = prosodyctl.deluser { user = user, host = host }; |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
386 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
387 if ok then return 0; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
388 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
389 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
390 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
391 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
392 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
393 function commands.start(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
394 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
395 show_usage([[start]], [[Start Prosody]]); |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
396 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
397 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
398 local ok, ret = prosodyctl.isrunning(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
399 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
400 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
401 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
402 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
403 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
404 if ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
405 local ok, ret = prosodyctl.getpid(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
406 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
407 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
|
408 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
409 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
410 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
411 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
|
412 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
413 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
414 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
415 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
|
416 if ok then |
5384
24f4aed5824f
prosody, prosodyctl: Remove last trace of "core" \o/
Kim Alvefur <zash@zash.se>
parents:
5296
diff
changeset
|
417 if config.get("*", "daemonize") ~= false 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
|
418 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 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
|
425 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
|
426 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 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
|
434 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
|
435 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
436 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
437 show_message("Failed to start Prosody"); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
438 show_message(error_messages[ret]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
439 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
440 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
441 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
442 function commands.status(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
443 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
444 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
|
445 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
446 end |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
447 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
448 local ok, ret = prosodyctl.isrunning(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
449 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
450 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
451 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
452 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
453 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
454 if ret then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
455 local ok, ret = prosodyctl.getpid(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
456 if not ok then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
457 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
|
458 show_message(error_messages[ret]); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
459 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
460 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
461 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
|
462 return 0; |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
463 else |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
464 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
|
465 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
|
466 print("\nNote:") |
07b2b5942957
prosodyctl: Reformat note to fit in small-width terminals
Matthew Wild <mwild1@gmail.com>
parents:
1120
diff
changeset
|
467 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
|
468 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
|
469 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
|
470 end |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
471 return 2 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
472 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
473 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
474 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
475 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
476 function commands.stop(arg) |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
477 if arg[1] == "--help" then |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
478 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
|
479 return 1; |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
480 end |
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
481 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
482 if not prosodyctl.isrunning() then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
483 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
|
484 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
485 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
486 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
487 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
|
488 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
|
489 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
|
490 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
|
491 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
|
492 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
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 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
|
499 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
|
500 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
|
501 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
|
502 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
|
503 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
|
504 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
|
505 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
506 |
1089
a817cbaa0f46
prosodyctl: Multiple fixes for start/status/stop
Matthew Wild <mwild1@gmail.com>
parents:
1087
diff
changeset
|
507 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
|
508 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
509 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
510 |
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
511 function commands.restart(arg) |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
512 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
|
513 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
|
514 return 1; |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
515 end |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
516 |
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
|
517 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
|
518 return commands.start(arg); |
2696
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
519 end |
cb5acafbec62
prosodyctl: Add restart command for KSid and johnny :)
Matthew Wild <mwild1@gmail.com>
parents:
2587
diff
changeset
|
520 |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
521 function commands.about(arg) |
4881
eafed1728be3
prosodyctl: Add duplicate code for getting version of prosody
Kim Alvefur <zash@zash.se>
parents:
4878
diff
changeset
|
522 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
|
523 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
|
524 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
|
525 return 1; |
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
526 end |
9c45858e3208
prosodyctl: Fix 'about' command to not show up where it shouldn't...
Matthew Wild <mwild1@gmail.com>
parents:
4324
diff
changeset
|
527 |
5023
dcc8e789df36
mod_admin_telnet, prosody, prosodyctl, ejabberd2prosody: Don't depend on modules setting globals
Florian Zeitz <florob@babelmonkeys.de>
parents:
4881
diff
changeset
|
528 local array = require "util.array"; |
4815
04e6115e060b
prosodyctl: Fix import of util.iterators
Kim Alvefur <zash@zash.se>
parents:
4487
diff
changeset
|
529 local keys = require "util.iterators".keys; |
4324
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
530 |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
531 print("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
|
532 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
533 print("# Prosody directories"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
534 print("Data directory: ", CFG_DATADIR or "./"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
535 print("Plugin directory:", CFG_PLUGINDIR or "./"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
536 print("Config directory:", CFG_CONFIGDIR or "./"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
537 print("Source directory:", CFG_SOURCEDIR or "./"); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
538 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
539 print("# 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
|
540 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
|
541 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
542 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
|
543 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
|
544 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
|
545 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
546 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
547 print("Lua 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
|
548 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
|
549 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
|
550 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
551 print(""); |
4333
040193dead77
prosodyctl: Add info about the presence of LuaRocks to 'about' command
Matthew Wild <mwild1@gmail.com>
parents:
4331
diff
changeset
|
552 local luarocks_status = (pcall(require, "luarocks.loader") and "Installed ("..(luarocks.cfg.program_version or "2.x+")..")") |
4334
cd1b73582711
prosodyctl: Remove typo'd '+' after LuaRocks 1.x version (thanks spoobie)
Matthew Wild <mwild1@gmail.com>
parents:
4333
diff
changeset
|
553 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
|
554 or "Not installed"; |
040193dead77
prosodyctl: Add info about the presence of LuaRocks to 'about' command
Matthew Wild <mwild1@gmail.com>
parents:
4331
diff
changeset
|
555 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
|
556 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
|
557 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
|
558 local module_versions, longest_name = {}, 8; |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
559 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
|
560 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
|
561 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
|
562 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
|
563 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
|
564 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
565 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
|
566 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
567 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
568 local sorted_keys = array.collect(keys(module_versions)):sort(); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
569 for _, name in ipairs(array.collect(keys(module_versions)):sort()) do |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
570 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
|
571 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
572 print(""); |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
573 end |
5e7cba840409
prosodyctl: Add 'about' command to list Prosody version, directories, and various other stuff
Matthew Wild <mwild1@gmail.com>
parents:
4167
diff
changeset
|
574 |
4335
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
575 function commands.reload(arg) |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
576 if arg[1] == "--help" then |
4476
53ce21286b8c
prosodyctl: Adjust description of 'reload' command (thanks crocket)
Matthew Wild <mwild1@gmail.com>
parents:
4336
diff
changeset
|
577 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
|
578 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
579 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
580 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
581 if not prosodyctl.isrunning() then |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
582 show_message("Prosody is not running"); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
583 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
584 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
585 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
586 local ok, ret = prosodyctl.reload(); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
587 if ok then |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
588 |
4336
abcbcb15205c
prosodyctl: Update message on reload success
Matthew Wild <mwild1@gmail.com>
parents:
4335
diff
changeset
|
589 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
|
590 return 0; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
591 end |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
592 |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
593 show_message(error_messages[ret]); |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
594 return 1; |
3a2a01432b5c
Add "reload" command to prosodyctl
Vladimir Protasov <eoranged@ya.ru>
parents:
4334
diff
changeset
|
595 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
596 -- ejabberdctl compatibility |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
597 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
598 function commands.register(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
599 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
|
600 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
|
601 if user ~= "--help" then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
602 if not user then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
603 show_message [[No username specified]] |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
604 elseif not host then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
605 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
|
606 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
607 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
608 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
|
609 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
610 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
611 if not password then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
612 password = read_password(); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
613 if not password then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
614 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
|
615 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
616 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
617 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
618 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
619 local ok, msg = prosodyctl.adduser { user = user, host = host, password = password }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
620 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
621 if ok then return 0; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
622 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
623 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
624 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
625 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
626 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
627 function commands.unregister(arg) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
628 local user, host = unpack(arg); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
629 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
|
630 if user ~= "--help" then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
631 if not user then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
632 show_message [[No username specified]] |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
633 elseif not host then |
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
634 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
|
635 end |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
636 end |
1102
c81df501fd38
prosodyctl: Hide ejabberd compatibility commands from command listing
Matthew Wild <mwild1@gmail.com>
parents:
1089
diff
changeset
|
637 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
|
638 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
639 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
640 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
641 local ok, msg = prosodyctl.deluser { user = user, host = host }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
642 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
643 if ok then return 0; end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
644 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
645 show_message(error_messages[msg]) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
646 return 1; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
647 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
648 |
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
|
649 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
|
650 local lfs; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
651 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
652 local cert_commands = {}; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
653 |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
654 local function ask_overwrite(filename) |
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
655 return lfs.attributes(filename) and not show_yesno("Overwrite "..filename .. "?"); |
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
656 end |
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
657 |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
658 function cert_commands.config(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
659 if #arg >= 1 and arg[1] ~= "--help" then |
5532
d5cbcdcdb2f7
prosodyctl: Put keys and certificates in ./certs when in a source checkout
Kim Alvefur <zash@zash.se>
parents:
5456
diff
changeset
|
660 local conf_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".cnf"; |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
661 if ask_overwrite(conf_filename) then |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
662 return nil, conf_filename; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
663 end |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
664 local conf = openssl.config.new(); |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
665 conf:from_prosody(hosts, config, arg); |
5545
d22416f8a836
prosodyctl: Add message describing the distinguished name input expected
Kim Alvefur <zash@zash.se>
parents:
5532
diff
changeset
|
666 show_message("Please provide details to include in the certificate config file."); |
d22416f8a836
prosodyctl: Add message describing the distinguished name input expected
Kim Alvefur <zash@zash.se>
parents:
5532
diff
changeset
|
667 show_message("Leave the field empty to use the default value or '.' to exclude the field.") |
5546
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
668 for i, k in ipairs(openssl._DN_order) do |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
669 local v = conf.distinguished_name[k]; |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
670 if v then |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
671 local nv; |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
672 if k == "commonName" then |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
673 v = arg[1] |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
674 elseif k == "emailAddress" then |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
675 v = "xmpp@" .. arg[1]; |
5547
f306daf2bf6d
prosodyctl: Guess the country from the TLD for the cert config
Kim Alvefur <zash@zash.se>
parents:
5546
diff
changeset
|
676 elseif k == "countryName" then |
f306daf2bf6d
prosodyctl: Guess the country from the TLD for the cert config
Kim Alvefur <zash@zash.se>
parents:
5546
diff
changeset
|
677 local tld = arg[1]:match"%.([a-z]+)$"; |
f306daf2bf6d
prosodyctl: Guess the country from the TLD for the cert config
Kim Alvefur <zash@zash.se>
parents:
5546
diff
changeset
|
678 if tld and #tld == 2 and tld ~= "uk" then |
f306daf2bf6d
prosodyctl: Guess the country from the TLD for the cert config
Kim Alvefur <zash@zash.se>
parents:
5546
diff
changeset
|
679 v = tld:upper(); |
f306daf2bf6d
prosodyctl: Guess the country from the TLD for the cert config
Kim Alvefur <zash@zash.se>
parents:
5546
diff
changeset
|
680 end |
5546
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
681 end |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
682 nv = show_prompt(("%s (%s):"):format(k, nv or v)); |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
683 nv = (not nv or nv == "") and v or nv; |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
684 if nv:find"[\192-\252][\128-\191]+" then |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
685 conf.req.string_mask = "utf8only" |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
686 end |
edc97af48d19
prosodyctl: Ask about the distinguished name in a in a consistent order
Kim Alvefur <zash@zash.se>
parents:
5545
diff
changeset
|
687 conf.distinguished_name[k] = nv ~= "." and nv or nil; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
688 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
689 end |
6035
1b5ca55bf895
prosodyctl: Show real error if certificate config file can't be opened
Kim Alvefur <zash@zash.se>
parents:
5547
diff
changeset
|
690 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
|
691 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
|
692 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
|
693 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
|
694 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
|
695 end |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
696 conf_file:write(conf:serialize()); |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
697 conf_file:close(); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
698 print(""); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
699 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
|
700 return nil, conf_filename; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
701 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
702 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
|
703 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
704 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
705 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
706 function cert_commands.key(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
707 if #arg >= 1 and arg[1] ~= "--help" then |
5532
d5cbcdcdb2f7
prosodyctl: Put keys and certificates in ./certs when in a source checkout
Kim Alvefur <zash@zash.se>
parents:
5456
diff
changeset
|
708 local key_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".key"; |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
709 if ask_overwrite(key_filename) then |
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
710 return nil, key_filename; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
711 end |
5151
dfe6a70efaa2
prosodyctl: Set stricter umask while generating key (thanks darkrain)
Kim Alvefur <zash@zash.se>
parents:
5150
diff
changeset
|
712 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
|
713 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
|
714 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
|
715 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
|
716 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
|
717 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
|
718 pposix.umask(old_umask); |
4824
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
719 return nil, key_filename; |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
720 end |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
721 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
|
722 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
723 show_usage("cert key HOSTNAME <bits>", "Generates a RSA key named HOSTNAME.key\n " |
4935 | 724 .."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
|
725 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
726 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
727 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
728 function cert_commands.request(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 |
5532
d5cbcdcdb2f7
prosodyctl: Put keys and certificates in ./certs when in a source checkout
Kim Alvefur <zash@zash.se>
parents:
5456
diff
changeset
|
730 local req_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".req"; |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
731 if ask_overwrite(req_filename) then |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
732 return nil, req_filename; |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
733 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
734 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
|
735 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
|
736 if openssl.req{new=true, key=key_filename, utf8=true, config=conf_filename, out=req_filename} then |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
737 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
|
738 else |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
739 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
|
740 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
741 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
742 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
|
743 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
744 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
745 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
746 function cert_commands.generate(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
747 if #arg >= 1 and arg[1] ~= "--help" then |
5532
d5cbcdcdb2f7
prosodyctl: Put keys and certificates in ./certs when in a source checkout
Kim Alvefur <zash@zash.se>
parents:
5456
diff
changeset
|
748 local cert_filename = (CFG_DATADIR or "./certs") .. "/" .. arg[1] .. ".crt"; |
4826
1c4852da78c8
prosodyctl: Replace hack with lfs for checking if a file exists
Kim Alvefur <zash@zash.se>
parents:
4824
diff
changeset
|
749 if ask_overwrite(cert_filename) then |
5152
fee5f8d4ec74
prosodyctl: Fix copypaste error
Kim Alvefur <zash@zash.se>
parents:
5151
diff
changeset
|
750 return nil, cert_filename; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
751 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
752 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
|
753 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
|
754 local ret; |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
755 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
|
756 and openssl.req{new=true, x509=true, nodes=true, key=key_filename, |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
757 days=365, sha1=true, utf8=true, config=conf_filename, out=cert_filename} then |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
758 show_message("Certificate written to ".. cert_filename); |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
759 else |
73e261ed00a9
prosodyctl: Use util.openssl in certificate helpers. Improve feedback
Kim Alvefur <zash@zash.se>
parents:
4815
diff
changeset
|
760 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
|
761 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
762 else |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
763 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
|
764 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
765 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
766 |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
767 function commands.cert(arg) |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
768 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
|
769 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
|
770 lfs = require "lfs"; |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
771 local subcmd = table.remove(arg, 1); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
772 if type(cert_commands[subcmd]) == "function" then |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
773 if not arg[1] then |
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
774 show_message"You need to supply at least one hostname" |
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
775 arg = { "--help" }; |
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
776 end |
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
777 if arg[1] ~= "--help" and not hosts[arg[1]] then |
4827
fefbfd76d2d3
prosodyctl: Show an error if the user doesn't supply a hostname to the certificate commands
Kim Alvefur <zash@zash.se>
parents:
4826
diff
changeset
|
778 show_message(error_messages["no-such-host"]); |
fefbfd76d2d3
prosodyctl: Show an error if the user doesn't supply a hostname to the certificate commands
Kim Alvefur <zash@zash.se>
parents:
4826
diff
changeset
|
779 return |
fefbfd76d2d3
prosodyctl: Show an error if the user doesn't supply a hostname to the certificate commands
Kim Alvefur <zash@zash.se>
parents:
4826
diff
changeset
|
780 end |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
781 return cert_commands[subcmd](arg); |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
782 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
783 end |
4872
b2059452fb55
prosodyctl: Improve help messages for cert commands
Kim Alvefur <zash@zash.se>
parents:
4827
diff
changeset
|
784 show_usage("cert config|request|generate|key", "Helpers for generating X.509 certificates and keys.") |
4487
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
785 end |
5f466a50e78b
prosodyctl: Add commands for generating certificates and keys
Kim Alvefur <zash@zash.se>
parents:
4476
diff
changeset
|
786 |
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
|
787 function commands.check(arg) |
5655
6d7f7548b2c9
prosodyctl: Add 'prosodyctl check --help'
Kim Alvefur <zash@zash.se>
parents:
5620
diff
changeset
|
788 if arg[1] == "--help" then |
6d7f7548b2c9
prosodyctl: Add 'prosodyctl check --help'
Kim Alvefur <zash@zash.se>
parents:
5620
diff
changeset
|
789 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
|
790 return 1; |
6d7f7548b2c9
prosodyctl: Add 'prosodyctl check --help'
Kim Alvefur <zash@zash.se>
parents:
5620
diff
changeset
|
791 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
|
792 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
|
793 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
|
794 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
|
795 local ok = true; |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
796 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
|
797 print("Checking config..."); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
798 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
|
799 "pidfile", "log", "plugin_paths", "prosody_user", "prosody_group", "daemonize", |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
800 "umask", "prosodyctl_timeout", "use_ipv6", "use_libevent", "network_settings" |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
801 }); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
802 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
|
803 -- 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
|
804 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
|
805 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
|
806 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
|
807 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
|
808 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
|
809 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
|
810 -- 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
|
811 local global_options = set.new(it.to_array(it.keys(config["*"]))); |
1d841117117c
prosodyctl: Add 'check' command, which currently checks the config file for some common mistakes
Matthew Wild <mwild1@gmail.com>
parents:
5554
diff
changeset
|
812 for host, options in it.filter("*", pairs(config)) 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
|
813 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
|
814 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
|
815 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
|
816 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
|
817 or name:match("_ports?$") or 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
|
818 or name:match("_ssl$") 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
|
819 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
|
820 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
|
821 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
|
822 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
|
823 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
|
824 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
|
825 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
|
826 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
|
827 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
|
828 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
|
829 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
|
830 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
|
831 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
|
832 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
|
833 if not(host_options:contains("component_module")) and (subdomain == "jabber" or subdomain == "xmpp" |
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
|
834 or subdomain == "chat" or subdomain == "im") then |
5617
783078bc111c
prosodyctl: check config: whitespace fix
Matthew Wild <mwild1@gmail.com>
parents:
5616
diff
changeset
|
835 print(""); |
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
|
836 print(" Suggestion: If "..host.. " is a new host with no real users yet, consider renaming it now to"); |
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
|
837 print(" "..host:gsub("^[^.]+%.", "")..". You can use SRV records to redirect XMPP clients and servers to "..host.."."); |
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
|
838 print(" For more information see: http://prosody.im/doc/dns"); |
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
|
839 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
|
840 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
|
841 |
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
|
842 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
|
843 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
|
844 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
|
845 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
|
846 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
|
847 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
|
848 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
|
849 local s2s_ports = set.new(config.get("*", "s2s_ports") or {5269}); |
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
|
850 |
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
|
851 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
|
852 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
|
853 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
|
854 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
|
855 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
|
856 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
|
857 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
|
858 |
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
|
859 local problem_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
|
860 |
5592
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
861 local external_addresses, internal_addresses = set.new(), set.new(); |
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
|
862 |
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
|
863 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
|
864 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
|
865 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
|
866 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
|
867 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
|
868 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
|
869 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
|
870 end |
5809
be997c6a69be
prosodyctl: check: Support for unicode (IDN) domains (thanks once again albert)
Matthew Wild <mwild1@gmail.com>
parents:
5723
diff
changeset
|
871 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
|
872 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
|
873 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
|
874 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
|
875 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
|
876 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
|
877 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
|
878 |
5723
24b6eb65480c
prosodyctl: Import local_addresses from the new util.net intead of luasocket
Kim Alvefur <zash@zash.se>
parents:
5657
diff
changeset
|
879 local local_addresses = require"util.net".local_addresses() or {}; |
5592
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
880 |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
881 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
|
882 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
|
883 external_addresses:add(addr); |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
884 else |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
885 internal_addresses:add(addr); |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
886 end |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
887 end |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
888 |
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
|
889 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
|
890 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
|
891 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
|
892 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
|
893 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
|
894 |
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
|
895 local v6_supported = not not socket.tcp6; |
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
|
896 |
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
|
897 for host, host_options in it.filter("*", pairs(config.getconfig())) 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
|
898 local all_targets_ok, some_targets_ok = true, 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
|
899 |
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
|
900 local is_component = not not host_options.component_module; |
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
|
901 print("Checking DNS for "..(is_component and "component" or "host").." "..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
|
902 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
|
903 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
|
904 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
|
905 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
|
906 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
|
907 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
|
908 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
|
909 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
|
910 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
|
911 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
|
912 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
|
913 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
|
914 print(" No _xmpp-client 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
|
915 all_targst_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
|
916 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
|
917 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
|
918 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
|
919 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
|
920 end |
5809
be997c6a69be
prosodyctl: check: Support for unicode (IDN) domains (thanks once again albert)
Matthew Wild <mwild1@gmail.com>
parents:
5723
diff
changeset
|
921 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
|
922 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
|
923 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
|
924 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
|
925 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
|
926 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
|
927 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
|
928 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
|
929 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
|
930 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
|
931 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
|
932 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
|
933 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
|
934 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
|
935 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
|
936 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
|
937 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
|
938 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
|
939 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
|
940 |
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
|
941 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
|
942 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
|
943 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
|
944 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
|
945 |
5620
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
946 local modules = set.new(it.to_array(it.values(host_options.modules_enabled))) |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
947 + set.new(it.to_array(it.values(config.get("*", "modules_enabled")))) |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
948 + 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
|
949 |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
950 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
|
951 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
|
952 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
|
953 local prob = {}; |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
954 if not A then |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
955 table.insert(prob, "A"); |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
956 end |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
957 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
|
958 table.insert(prob, "AAAA"); |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
959 end |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
960 if #prob > 0 then |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
961 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
|
962 end |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
963 end |
8349ae2a44ce
prosodyctl: check dns: Add check that proxy65 addresses resolve correctly
Matthew Wild <mwild1@gmail.com>
parents:
5619
diff
changeset
|
964 |
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
|
965 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
|
966 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
|
967 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
|
968 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
|
969 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
|
970 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
|
971 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
|
972 host_ok_v4 = true; |
5592
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
973 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
|
974 host_ok_v4 = true; |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
975 some_targets_ok = true; |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
976 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
|
977 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
|
978 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
|
979 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
|
980 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
|
981 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
|
982 end |
5809
be997c6a69be
prosodyctl: check: Support for unicode (IDN) domains (thanks once again albert)
Matthew Wild <mwild1@gmail.com>
parents:
5723
diff
changeset
|
983 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
|
984 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
|
985 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
|
986 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
|
987 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
|
988 host_ok_v6 = true; |
5592
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
989 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
|
990 host_ok_v6 = true; |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
991 some_targets_ok = true; |
5705e21ba24b
prosodyctl: check dns: Use socket.local_addresses() if available
Matthew Wild <mwild1@gmail.com>
parents:
5591
diff
changeset
|
992 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
|
993 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
|
994 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
|
995 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
|
996 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
|
997 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
|
998 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
|
999 |
5590
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1000 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
|
1001 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
|
1002 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
|
1003 end |
5590
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1004 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
|
1005 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
|
1006 end |
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1007 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
|
1008 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
|
1009 end |
597450c73ce6
prosodyctl: check dns: More concise output (merged separate v4/v6 warnings)
Matthew Wild <mwild1@gmail.com>
parents:
5589
diff
changeset
|
1010 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
|
1011 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
|
1012 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
|
1013 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
|
1014 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
|
1015 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
|
1016 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
|
1017 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
|
1018 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
|
1019 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
|
1020 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
|
1021 end |
5591
f0bf2a1790d9
prosodyctl: check dns: Whitespace fix in output
Matthew Wild <mwild1@gmail.com>
parents:
5590
diff
changeset
|
1022 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
|
1023 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
|
1024 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
|
1025 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
|
1026 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
|
1027 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
|
1028 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
|
1029 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
|
1030 end |
5657
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1031 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
|
1032 local cert_ok; |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1033 print"Checking certificates..." |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1034 local x509_verify_identity = require"util.x509".verify_identity; |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1035 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
|
1036 -- local datetime_parse = require"util.datetime".parse_x509; |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1037 local load_cert = ssl and ssl.x509 and ssl.x509.load; |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1038 -- 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
|
1039 if not ssl then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1040 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
|
1041 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
|
1042 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
|
1043 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
|
1044 cert_ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1045 else |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1046 for host in pairs(hosts) do |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1047 if host ~= "*" then -- Should check global certs too. |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1048 print("Checking certificate for "..host); |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1049 -- First, let's find out what certificate this host uses. |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1050 local ssl_config = config.rawget(host, "ssl"); |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1051 if not ssl_config then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1052 local base_host = host:match("%.(.*)"); |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1053 ssl_config = config.get(base_host, "ssl"); |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1054 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1055 if not ssl_config then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1056 print(" No 'ssl' option defined for "..host) |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1057 cert_ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1058 elseif not ssl_config.certificate then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1059 print(" No 'certificate' set in ssl option for "..host) |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1060 cert_ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1061 elseif not ssl_config.key then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1062 print(" No 'key' set in ssl option for "..host) |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1063 cert_ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1064 else |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1065 local key, err = io.open(ssl_config.key); -- Permissions check only |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1066 if not key then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1067 print(" Could not open "..ssl_config.key..": "..err); |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1068 cert_ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1069 else |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1070 key:close(); |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1071 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1072 local cert_fh, err = io.open(ssl_config.certificate); -- Load the file. |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1073 if not cert_fh then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1074 print(" Could not open "..ssl_config.certificate..": "..err); |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1075 cert_ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1076 else |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1077 print(" Certificate: "..ssl_config.certificate) |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1078 local cert = load_cert(cert_fh:read"*a"); cert_fh = cert_fh:close(); |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1079 if not cert:validat(os.time()) then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1080 print(" Certificate has expired.") |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1081 cert_ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1082 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1083 if config.get(host, "component_module") == nil |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1084 and not x509_verify_identity(host, "_xmpp-client", cert) then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1085 print(" Not vaild for client connections to "..host..".") |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1086 cert_ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1087 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1088 if (not (config.get(name, "anonymous_login") |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1089 or config.get(name, "authentication") == "anonymous")) |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1090 and not x509_verify_identity(host, "_xmpp-client", cert) then |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1091 print(" Not vaild for server-to-server connections to "..host..".") |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1092 cert_ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1093 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1094 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1095 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1096 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1097 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1098 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
|
1099 print("") |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1100 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
|
1101 ok = false |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1102 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1103 end |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1104 print("") |
7957f14038e8
prosodyctl: Add 'prosodyctl check certs' for validating TLS/SSL certificates
Kim Alvefur <zash@zash.se>
parents:
5655
diff
changeset
|
1105 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
|
1106 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
|
1107 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
|
1108 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
|
1109 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
|
1110 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
|
1111 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
|
1112 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
|
1113 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1114 --------------------- |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1115 |
1499
51e3e22b5316
prosodyctl: Fix traceback when issued with no parameters
Matthew Wild <mwild1@gmail.com>
parents:
1460
diff
changeset
|
1116 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
|
1117 local module_name = command:match("^mod_(.+)"); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1118 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
|
1119 if not ret then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1120 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
|
1121 os.exit(1); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1122 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1123 |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1124 table.remove(arg, 1); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1125 |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1126 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
|
1127 if not module then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1128 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
|
1129 os.exit(1); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1130 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1131 |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1132 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
|
1133 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
|
1134 os.exit(1); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1135 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1136 |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1137 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
|
1138 if ok then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1139 if type(ret) == "number" then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1140 os.exit(ret); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1141 elseif type(ret) == "string" then |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1142 show_message(ret); |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1143 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1144 os.exit(0); -- :) |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1145 else |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1146 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
|
1147 os.exit(1); -- :( |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1148 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1149 end |
ef672c9fe7c9
prosodyctl: Allow commands to be implemented in modules
Matthew Wild <mwild1@gmail.com>
parents:
1205
diff
changeset
|
1150 |
1087
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1151 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
|
1152 function show_usage(usage, desc) |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1153 print(" "..usage); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1154 print(" "..desc); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1155 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1156 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1157 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
|
1158 print(""); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1159 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
|
1160 print(""); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1161 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
|
1162 |
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
|
1163 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
|
1164 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
|
1165 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1166 local done = {}; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1167 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1168 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
|
1169 local command = commands[command_name]; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1170 if command then |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1171 command{ "--help" }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1172 print"" |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1173 done[command_name] = true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1174 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1175 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1176 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1177 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
|
1178 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
|
1179 command{ "--help" }; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1180 print"" |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1181 done[command_name] = true; |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1182 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1183 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1184 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1185 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1186 os.exit(0); |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1187 end |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1188 |
5e9475bec571
prosodyctl, util.prosodyctl: New prosodyctl utility for managing Prosody servers
Matthew Wild <mwild1@gmail.com>
parents:
diff
changeset
|
1189 os.exit(commands[command]({ select(2, unpack(arg)) })); |