~samwhited/xmpp

ref: 54b1b91fda7ff275377bed583d27b1746d192a41 xmpp/internal/integration/prosody/config.go -rw-r--r-- 4.2 KiB
54b1b91fSam Whited muc: fix broken tests 3 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2020 The Mellium Contributors.
// Use of this source code is governed by the BSD 2-clause
// license that can be found in the LICENSE file.

package prosody

import (
	"fmt"
	"path/filepath"
	"strings"
	"text/template"
)

// Config contains options that can be written to a Prosody config file.
type Config struct {
	C2SPort   int
	S2SPort   int
	CompPort  int
	HTTPPort  int
	HTTPSPort int
	Admins    []string
	Modules   []string
	VHosts    []string
	Options   map[string]interface{}
	Component map[string]struct {
		Name    string
		Secret  string
		Modules []string
	}
}

const cfgBase = `daemonize = false
pidfile = "{{ filepathJoin .ConfigDir "prosody.pid" }}"
admins = { {{ joinQuote .Admins }} }
data_path = "{{ .ConfigDir }}"
interfaces = { "::1", "127.0.0.1" }
http_interfaces = { "::1", "127.0.0.1" }
https_interfaces = { "::1", "127.0.0.1" }
{{ if .C2SPort }}c2s_ports = { {{ .C2SPort }} }{{ end }}
{{ if .S2SPort }}s2s_ports = { {{ .S2SPort }} }{{ end }}
{{ if .CompPort }}component_ports = { {{.CompPort}} }{{ end }}
{{ if .HTTPPort }}http_ports = { {{.HTTPPort}} }{{ end }}
{{ if .HTTPSPort }}https_ports = { {{.HTTPSPort}} }{{ end }}

-- Settings added with prosody.Set:
{{ range $k, $opt := .Options }}
{{ $k }}{{ if $opt }} = {{ quoteOrPrint $opt }}{{ end }}
{{ else }}
-- Set not called.
{{ end }}

cross_domain_websocket = true
consider_websocket_secure = true

modules_enabled = {
	-- Extra modules added with prosody.Modules:
		{{ luaList .Modules }}

	-- Generally required
		"roster"; -- Allow users to have a roster. Recommended ;)
		"saslauth"; -- Authentication for clients and servers. Recommended if you want to log in.
		"tls"; -- Add support for secure TLS on c2s/s2s connections
		"disco"; -- Service discovery

	-- Not essential, but recommended
		"carbons"; -- Keep multiple clients in sync
		"pep"; -- Enables users to publish their avatar, mood, activity, playing music and more
		"private"; -- Private XML storage (for room bookmarks, etc.)
		"blocklist"; -- Allow users to block communications with other users
		"vcard4"; -- User profiles (stored in PEP)
		"vcard_legacy"; -- Conversion between legacy vCard and PEP Avatar, vcard

	-- Nice to have
		"version"; -- Replies to server version requests
		"uptime"; -- Report how long server has been running
		"time"; -- Let others know the time here on this server
		"ping"; -- Replies to XMPP pings with pongs
		"register"; -- Allow users to register on this server using a client and change passwords

	-- Admin interfaces
		"admin_adhoc"; -- Allows administration via an XMPP client that supports ad-hoc commands
}

modules_disabled = {
  {{ if not .C2SPort }}"c2s";{{ end }}
  {{ if not .S2SPort }}"s2s";{{ end }}
}

plugin_paths = { "{{ .ConfigDir }}" }
allow_registration = false
c2s_require_encryption = true
s2s_require_encryption = true
s2s_secure_auth = false
s2s_insecure_domains = { {{ joinQuote .VHosts }} }
authentication = "internal_plain"
storage = "internal"

log = {
	{ levels = { min = "info" }, to = "console" };
	{ levels = { min = "debug" }, to = "file", filename = "{{ filepathJoin .ConfigDir "prosody.log" }}" };
}

statistics = "internal"
certificates = "{{ .ConfigDir }}"
{{ if .HTTPSPort }}https_certificate = "{{ filepathJoin .ConfigDir "localhost:" }}{{ .HTTPSPort }}.crt"{{ end }}

{{- range .VHosts }}
VirtualHost "{{ . }}"
{{- end }}

{{ range $domain, $cfg := .Component }}
Component "{{$domain}}" {{if $cfg.Name}}"{{$cfg.Name}}"{{end}}
				 {{if $cfg.Modules}}modules_enabled = { {{ luaList $cfg.Modules }} }{{end}}
				 {{if $cfg.Secret}}component_secret = "{{$cfg.Secret}}"{{end}}
{{ end }}`

var cfgTmpl = template.Must(template.New("cfg").Funcs(template.FuncMap{
	"filepathJoin": filepath.Join,
	"joinQuote": func(s []string) string {
		s = append(s[:0:0], s...)
		for i, ss := range s {
			s[i] = fmt.Sprintf("%q", ss)
		}
		return strings.Join(s, ",")
	},
	"luaList": func(s []string) string {
		s = append(s[:0:0], s...)
		for i, ss := range s {
			s[i] = fmt.Sprintf("%q", ss)
		}
		var end string
		if len(s) > 0 {
			end = ";\n"
		}
		return strings.Join(s, ";\n") + end
	},
	"quoteOrPrint": func(v interface{}) string {
		switch vv := v.(type) {
		case string:
			return fmt.Sprintf("%q", vv)
		default:
			return fmt.Sprintf("%v", vv)
		}
	},
}).Parse(cfgBase))