Software /
code /
prosody
Comparison
tools/cfgdump.lua @ 11192:11f285a439a4
tools/cfgdump: Reads Prosody config file and pretty-prints it back out
Useful for comparing what you think you have in your config with what
Prosody sees, e.g. wrt (lack of) significance of indentation, order of
options vs scope etc. (global options do not go at the end!)
Could probably be turned into a prosodyctl command, especially if it
learns to redact secrets and passwords.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Wed, 28 Oct 2020 22:48:31 +0100 |
child | 11569:08dab7df152b |
comparison
equal
deleted
inserted
replaced
11191:13e2ac7b5798 | 11192:11f285a439a4 |
---|---|
1 #!/usr/bin/env lua | |
2 | |
3 -- cfgdump.lua prosody.cfg.lua [[host] option] | |
4 | |
5 local s_format, print = string.format, print; | |
6 local printf = function(fmt, ...) return print(s_format(fmt, ...)); end | |
7 local serialization = require"util.serialization"; | |
8 local serialize = serialization.new and serialization.new({ unquoted = true }) or serialization.serialize; | |
9 local configmanager = require"core.configmanager"; | |
10 local startup = require "util.startup"; | |
11 | |
12 startup.set_function_metatable(); | |
13 local config_filename, onlyhost, onlyoption = ...; | |
14 | |
15 local ok, _, err = configmanager.load(config_filename or "./prosody.cfg.lua", "lua"); | |
16 assert(ok, err); | |
17 | |
18 if onlyhost then | |
19 if not onlyoption then | |
20 onlyhost, onlyoption = "*", onlyhost; | |
21 end | |
22 if onlyhost ~= "*" then | |
23 local component_module = configmanager.get(onlyhost, "component_module"); | |
24 | |
25 if component_module == "component" then | |
26 printf("Component %q", onlyhost); | |
27 elseif component_module then | |
28 printf("Component %q %q", onlyhost, component_module); | |
29 else | |
30 printf("VirtualHost %q", onlyhost); | |
31 end | |
32 end | |
33 printf("%s = %s", onlyoption or "?", serialize(configmanager.get(onlyhost, onlyoption))); | |
34 return; | |
35 end | |
36 | |
37 local config = configmanager.getconfig(); | |
38 | |
39 | |
40 for host, hostcfg in pairs(config) do | |
41 local fixed = {}; | |
42 for option, value in pairs(hostcfg) do | |
43 fixed[option] = value; | |
44 if option:match("ports?$") or option:match("interfaces?$") then | |
45 if option:match("s$") then | |
46 if type(value) ~= "table" then | |
47 fixed[option] = { value }; | |
48 end | |
49 else | |
50 if type(value) == "table" and #value > 1 then | |
51 fixed[option] = nil; | |
52 fixed[option.."s"] = value; | |
53 end | |
54 end | |
55 end | |
56 end | |
57 config[host] = fixed; | |
58 end | |
59 | |
60 local globals = config["*"]; config["*"] = nil; | |
61 | |
62 local function printsection(section) | |
63 local out, n = {}, 1; | |
64 for k,v in pairs(section) do | |
65 out[n], n = s_format("%s = %s", k, serialize(v)), n + 1; | |
66 end | |
67 table.sort(out); | |
68 print(table.concat(out, "\n")); | |
69 end | |
70 | |
71 print("-------------- Prosody Exported Configuration File -------------"); | |
72 print(); | |
73 print("------------------------ Global section ------------------------"); | |
74 print(); | |
75 printsection(globals); | |
76 print(); | |
77 | |
78 local has_components = nil; | |
79 | |
80 print("------------------------ Virtual hosts -------------------------"); | |
81 | |
82 for host, hostcfg in pairs(config) do | |
83 setmetatable(hostcfg, nil); | |
84 hostcfg.defined = nil; | |
85 | |
86 if hostcfg.component_module == nil then | |
87 print(); | |
88 printf("VirtualHost %q", host); | |
89 printsection(hostcfg); | |
90 else | |
91 has_components = true | |
92 end | |
93 end | |
94 | |
95 print(); | |
96 | |
97 if has_components then | |
98 print("------------------------- Components ---------------------------"); | |
99 | |
100 for host, hostcfg in pairs(config) do | |
101 local component_module = hostcfg.component_module; | |
102 hostcfg.component_module = nil; | |
103 | |
104 if component_module then | |
105 print(); | |
106 if component_module == "component" then | |
107 printf("Component %q", host); | |
108 else | |
109 printf("Component %q %q", host, component_module); | |
110 hostcfg.component_module = nil; | |
111 hostcfg.load_global_modules = nil; | |
112 end | |
113 printsection(hostcfg); | |
114 end | |
115 end | |
116 end | |
117 | |
118 print() | |
119 print("------------------------- End of File --------------------------"); | |
120 |