XMPP clients connections WIP:

* new option to allow external xmpp account s2s connections
* settings to setup the port and network interfaces
* documentation WIP

Related to issue #114
This commit is contained in:
John Livingston
2023-04-07 18:27:15 +02:00
committed by John Livingston
parent c81c2eb9bb
commit 4d9d9d39b0
14 changed files with 212 additions and 2 deletions

View File

@ -102,6 +102,9 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
'prosody-muc-expiration',
'prosody-c2s',
'prosody-c2s-port',
'prosody-room-allow-s2s',
'prosody-s2s-port',
'prosody-s2s-interfaces',
'prosody-room-type',
'prosody-peertube-uri',
'prosody-components',
@ -118,7 +121,8 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
const logByDefault = (settings['prosody-muc-log-by-default'] as boolean) ?? true
const disableAnon = (settings['chat-no-anonymous'] as boolean) || false
const logExpirationSetting = (settings['prosody-muc-expiration'] as string) ?? DEFAULTLOGEXPIRATION
const enableC2s = (settings['prosody-c2s'] as boolean) || false
const enableC2S = (settings['prosody-c2s'] as boolean) || false
const enableRoomS2S = (settings['prosody-room-allow-s2s'] as boolean) || false
const enableComponents = (settings['prosody-components'] as boolean) || false
const prosodyDomain = await getProsodyDomain(options)
const paths = await getProsodyFilePaths(options)
@ -149,7 +153,7 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
config.usePeertubeBoshAndWebsocket(prosodyDomain, port, options.peertubeHelpers.config.getWebserverUrl(), useWS)
config.useMucHttpDefault(roomApiUrl)
if (enableC2s) {
if (enableC2S) {
const c2sPort = (settings['prosody-c2s-port'] as string) || '52822'
if (!/^\d+$/.test(c2sPort)) {
throw new Error('Invalid c2s port')
@ -169,6 +173,25 @@ async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<Pros
config.useExternalComponents(componentsPort, components)
}
if (enableRoomS2S) {
const s2sPort = (settings['prosody-s2s-port'] as string) || '5269'
if (!/^\d+$/.test(s2sPort)) {
throw new Error('Invalid s2s port')
}
const s2sInterfaces = ((settings['prosody-s2s-interfaces'] as string) || '')
.split(',')
.map(s => s.trim())
// Check that there is no invalid values (to avoid injections):
s2sInterfaces.forEach(networkInterface => {
if (networkInterface === '*') return
if (networkInterface === '::') return
if (networkInterface.match(/^\d+\.\d+\.\d+\.\d+$/)) return
if (networkInterface.match(/^[a-f0-9:]+$/)) return
throw new Error('Invalid s2s interfaces')
})
config.useRoomS2S(s2sPort, s2sInterfaces)
}
const logExpiration = readLogExpiration(options, logExpirationSetting)
config.useMam(logByDefault, logExpiration)
// TODO: add a settings to choose?

View File

@ -257,6 +257,12 @@ class ProsodyConfigContent {
this.global.set('c2s_ports', [c2sPort])
}
useRoomS2S (s2sPort: string, s2sInterfaces: string[]): void {
this.global.set('s2s_ports', [s2sPort])
this.global.set('s2s_interfaces', s2sInterfaces)
this.muc.add('modules_enabled', 's2s')
}
useExternalComponents (componentsPort: string, components: ExternalComponent[]): void {
this.global.set('component_ports', [componentsPort])
this.global.set('component_interfaces', ['127.0.0.1', '::1'])

View File

@ -302,6 +302,33 @@ Please read
descriptionHTML: loc('prosody_muc_expiration_description')
})
registerSetting({
name: 'prosody-room-allow-s2s',
label: loc('prosody_room_allow_s2s_label'),
type: 'input-checkbox',
default: false,
private: true,
descriptionHTML: loc('prosody_room_allow_s2s_description')
})
registerSetting({
name: 'prosody-s2s-port',
label: loc('prosody_s2s_port_label'),
type: 'input',
default: '5269',
private: true,
descriptionHTML: loc('prosody_s2s_port_description')
})
registerSetting({
name: 'prosody-s2s-interfaces',
label: loc('prosody_s2s_interfaces_label'),
type: 'input',
default: '*, ::',
private: true,
descriptionHTML: loc('prosody_s2s_interfaces_description')
})
registerSetting({
name: 'prosody-c2s',
label: loc('prosody_c2s_label'),