2024-05-23 09:42:14 +00:00
|
|
|
// SPDX-FileCopyrightText: 2024 John Livingston <https://www.john-livingston.fr/>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-04-30 14:22:58 +00:00
|
|
|
import type { ProsodyFilePaths } from './paths'
|
2021-12-11 18:09:01 +00:00
|
|
|
import type { ExternalComponent } from './components'
|
2023-09-19 13:54:56 +00:00
|
|
|
import { BotConfiguration } from '../../configuration/bot'
|
2023-06-08 08:22:43 +00:00
|
|
|
import { userInfo } from 'os'
|
2021-04-30 14:22:58 +00:00
|
|
|
|
2024-06-25 07:59:46 +00:00
|
|
|
/**
|
|
|
|
* Use this class to construct a string that will be writen as a multiline Lua string.
|
|
|
|
*/
|
|
|
|
class ConfigEntryValueMultiLineString extends String {
|
|
|
|
public serialize (): string {
|
|
|
|
const s = this.toString()
|
|
|
|
let i = 0
|
|
|
|
// Lua multiline strings can be escaped by [[ ]], or [==[ ]==] with any number of =
|
|
|
|
// http://lua-users.org/wiki/StringsTutorial
|
|
|
|
// So, to have a proper value, we will check if the string contains [[ or ]],
|
|
|
|
// and try again by adding "=" until we do not found the pattern.
|
|
|
|
while (true) {
|
|
|
|
const opening = '[' + '='.repeat(i) + '['
|
|
|
|
const closing = ']' + '='.repeat(i) + ']'
|
|
|
|
if (!s.includes(opening) && !s.includes(closing)) {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
i++
|
|
|
|
}
|
|
|
|
return '[' + '='.repeat(i) + '[' + s + ']' + '='.repeat(i) + ']'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ConfigEntryValue = boolean | number | string | ConfigEntryValueMultiLineString | ConfigEntryValue[]
|
2021-04-30 14:22:58 +00:00
|
|
|
|
2021-05-04 14:43:38 +00:00
|
|
|
type ConfigEntries = Map<string, ConfigEntryValue>
|
2021-04-30 14:22:58 +00:00
|
|
|
|
2021-12-01 11:57:15 +00:00
|
|
|
interface ConfigLogExpirationNever {
|
|
|
|
value: 'never'
|
|
|
|
type: 'never'
|
|
|
|
}
|
|
|
|
interface ConfigLogExpirationSeconds {
|
|
|
|
value: string
|
|
|
|
seconds: number
|
|
|
|
type: 'seconds'
|
|
|
|
}
|
|
|
|
interface ConfigLogExpirationPeriod {
|
|
|
|
value: string
|
|
|
|
type: 'period'
|
|
|
|
}
|
|
|
|
interface ConfigLogExpirationError {
|
|
|
|
value: string
|
|
|
|
error: string
|
|
|
|
type: 'period'
|
|
|
|
}
|
|
|
|
type ConfigLogExpiration =
|
|
|
|
ConfigLogExpirationNever | ConfigLogExpirationPeriod | ConfigLogExpirationSeconds | ConfigLogExpirationError
|
|
|
|
|
2021-04-30 14:22:58 +00:00
|
|
|
function writeValue (value: ConfigEntryValue): string {
|
2024-06-25 07:59:46 +00:00
|
|
|
if (value instanceof ConfigEntryValueMultiLineString) {
|
|
|
|
return value.serialize() + ';\n'
|
|
|
|
}
|
2021-04-30 14:22:58 +00:00
|
|
|
if (typeof value === 'boolean') {
|
|
|
|
return value.toString() + ';\n'
|
|
|
|
}
|
|
|
|
if (typeof value === 'string') {
|
|
|
|
return '"' + value.replace(/"/g, '\\"') + '"' + ';\n'
|
|
|
|
}
|
|
|
|
if (typeof value === 'number') {
|
|
|
|
return value.toString() + ';\n'
|
|
|
|
}
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
let s = '{\n'
|
|
|
|
for (let i = 0; i < value.length; i++) {
|
|
|
|
s += ' ' + writeValue(value[i])
|
|
|
|
}
|
|
|
|
s += '};\n'
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
throw new Error(`Don't know how to handle this value: ${value as string}`)
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class ProsodyConfigBlock {
|
|
|
|
entries: ConfigEntries
|
|
|
|
prefix: string
|
|
|
|
|
|
|
|
constructor (prefix: string) {
|
|
|
|
this.prefix = prefix
|
2021-05-04 14:43:38 +00:00
|
|
|
this.entries = new Map()
|
2021-04-30 14:22:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
set (name: string, value: ConfigEntryValue): void {
|
2021-05-04 14:43:38 +00:00
|
|
|
this.entries.set(name, value)
|
2021-04-30 14:22:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
add (name: string, value: ConfigEntryValue): void {
|
2021-05-04 14:43:38 +00:00
|
|
|
if (!this.entries.has(name)) {
|
|
|
|
this.entries.set(name, [])
|
2021-04-30 14:22:58 +00:00
|
|
|
}
|
2021-05-04 14:43:38 +00:00
|
|
|
let entry = this.entries.get(name) as ConfigEntryValue
|
2021-04-30 14:22:58 +00:00
|
|
|
if (!Array.isArray(entry)) {
|
|
|
|
entry = [entry]
|
|
|
|
}
|
|
|
|
entry.push(value)
|
2021-05-04 14:43:38 +00:00
|
|
|
this.entries.set(name, entry)
|
2021-04-30 14:22:58 +00:00
|
|
|
}
|
|
|
|
|
2023-05-19 10:52:52 +00:00
|
|
|
remove (name: string, value: ConfigEntryValue): void {
|
|
|
|
if (!this.entries.has(name)) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
let entry = this.entries.get(name) as ConfigEntryValue
|
|
|
|
if (!Array.isArray(entry)) {
|
|
|
|
entry = [entry]
|
|
|
|
}
|
|
|
|
entry = entry.filter(v => v !== value)
|
|
|
|
this.entries.set(name, entry)
|
|
|
|
}
|
|
|
|
|
2021-04-30 14:22:58 +00:00
|
|
|
write (): string {
|
|
|
|
let content = ''
|
2021-05-04 14:43:38 +00:00
|
|
|
// Map keeps order :)
|
|
|
|
this.entries.forEach((value, key) => {
|
|
|
|
content += this.prefix + key + ' = ' + writeValue(value)
|
2021-04-30 14:22:58 +00:00
|
|
|
})
|
|
|
|
return content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProsodyConfigGlobal extends ProsodyConfigBlock {
|
|
|
|
constructor () {
|
|
|
|
super('')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProsodyConfigVirtualHost extends ProsodyConfigBlock {
|
|
|
|
name: string
|
|
|
|
|
|
|
|
constructor (name: string) {
|
|
|
|
super(' ')
|
|
|
|
this.name = name
|
|
|
|
}
|
|
|
|
|
2024-05-25 12:39:45 +00:00
|
|
|
override write (): string {
|
2021-04-30 14:22:58 +00:00
|
|
|
return `VirtualHost "${this.name}"\n` + super.write()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ProsodyConfigComponent extends ProsodyConfigBlock {
|
|
|
|
name: string
|
2021-12-11 18:09:01 +00:00
|
|
|
type?: string
|
2021-04-30 14:22:58 +00:00
|
|
|
|
2021-12-11 18:09:01 +00:00
|
|
|
constructor (name: string, type?: string) {
|
2021-04-30 14:22:58 +00:00
|
|
|
super(' ')
|
|
|
|
this.type = type
|
|
|
|
this.name = name
|
|
|
|
}
|
|
|
|
|
2024-05-25 12:39:45 +00:00
|
|
|
override write (): string {
|
2021-12-11 18:09:01 +00:00
|
|
|
if (this.type !== undefined) {
|
|
|
|
return `Component "${this.name}" "${this.type}"\n` + super.write()
|
|
|
|
}
|
|
|
|
return `Component "${this.name}"\n` + super.write()
|
2021-04-30 14:22:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-12 09:48:38 +00:00
|
|
|
type ProsodyLogLevel = 'debug' | 'info' | 'warn' | 'error'
|
2021-04-30 14:22:58 +00:00
|
|
|
|
|
|
|
class ProsodyConfigContent {
|
|
|
|
paths: ProsodyFilePaths
|
|
|
|
global: ProsodyConfigGlobal
|
2021-05-03 18:37:23 +00:00
|
|
|
authenticated?: ProsodyConfigVirtualHost
|
2022-04-11 16:12:12 +00:00
|
|
|
anon?: ProsodyConfigVirtualHost
|
2024-04-17 14:35:26 +00:00
|
|
|
external?: ProsodyConfigVirtualHost
|
2021-04-30 14:22:58 +00:00
|
|
|
muc: ProsodyConfigComponent
|
2023-09-18 16:53:07 +00:00
|
|
|
bot?: ProsodyConfigVirtualHost
|
2021-12-11 18:09:01 +00:00
|
|
|
externalComponents: ProsodyConfigComponent[] = []
|
2021-04-30 14:22:58 +00:00
|
|
|
log: string
|
2021-05-06 11:31:55 +00:00
|
|
|
prosodyDomain: string
|
2021-04-30 14:22:58 +00:00
|
|
|
|
2024-06-25 07:59:46 +00:00
|
|
|
constructor (paths: ProsodyFilePaths, prosodyDomain: string, chatTerms?: string) {
|
2021-04-30 14:22:58 +00:00
|
|
|
this.paths = paths
|
|
|
|
this.global = new ProsodyConfigGlobal()
|
|
|
|
this.log = ''
|
2021-05-06 11:31:55 +00:00
|
|
|
this.prosodyDomain = prosodyDomain
|
2021-12-11 18:09:01 +00:00
|
|
|
this.muc = new ProsodyConfigComponent('room.' + prosodyDomain, 'muc')
|
2021-04-30 14:22:58 +00:00
|
|
|
|
|
|
|
this.global.set('daemonize', false)
|
|
|
|
this.global.set('allow_registration', false)
|
|
|
|
this.global.set('admins', [])
|
|
|
|
|
2023-06-08 08:22:43 +00:00
|
|
|
this.global.set('prosody_user', userInfo().username)
|
|
|
|
|
2021-04-30 14:22:58 +00:00
|
|
|
this.global.set('pidfile', this.paths.pid)
|
|
|
|
this.global.set('plugin_paths', [this.paths.modules])
|
|
|
|
this.global.set('data_path', this.paths.data)
|
2023-04-11 15:07:43 +00:00
|
|
|
// this.global.set('default_storage', 'internal') Not needed as storage is set to a string
|
2021-04-30 16:00:21 +00:00
|
|
|
this.global.set('storage', 'internal')
|
2021-04-30 14:22:58 +00:00
|
|
|
|
|
|
|
this.global.set('modules_enabled', [
|
|
|
|
'roster', // Allow users to have a roster. Recommended ;)
|
|
|
|
'saslauth', // Authentication for clients and servers. Recommended if you want to log in.
|
2021-05-04 11:16:59 +00:00
|
|
|
'carbons', // Keep multiple clients in sync
|
2021-04-30 14:22:58 +00:00
|
|
|
'version', // Replies to server version requests
|
|
|
|
'uptime', // Report how long server has been running
|
|
|
|
'ping', // Replies to XMPP pings with pongs
|
2023-09-18 16:53:07 +00:00
|
|
|
// 'bosh', // Enable BOSH clients, aka "Jabber over HTTP"
|
2022-08-25 11:44:35 +00:00
|
|
|
// 'websocket', // Enable Websocket clients
|
2022-11-01 09:35:42 +00:00
|
|
|
'posix', // POSIX functionality, sends server to background, enables syslog, etc.
|
2022-01-05 17:53:44 +00:00
|
|
|
// 'pep', // Enables users to publish their avatar, mood, activity, playing music and more
|
|
|
|
// 'vcard_legacy' // Conversion between legacy vCard and PEP Avatar, vcard
|
2022-01-05 01:01:54 +00:00
|
|
|
// 'vcard4' // User profiles (stored in PEP)
|
2022-11-01 09:35:42 +00:00
|
|
|
'disco' // Enable mod_disco (feature discovering)
|
2021-04-30 14:22:58 +00:00
|
|
|
])
|
|
|
|
this.global.set('modules_disabled', [
|
|
|
|
// 'offline' // Store offline messages
|
|
|
|
// 'c2s' // Handle client connections
|
|
|
|
's2s' // Handle server-to-server connections
|
|
|
|
])
|
|
|
|
|
2023-04-11 15:07:43 +00:00
|
|
|
// this.global.set('cross_domain_bosh', false) No more needed with Prosody 0.12
|
2021-04-30 14:22:58 +00:00
|
|
|
this.global.set('consider_bosh_secure', false)
|
2023-04-11 15:07:43 +00:00
|
|
|
// this.global.set('cross_domain_websocket', false) No more needed with Prosody 0.12
|
2021-04-30 14:22:58 +00:00
|
|
|
this.global.set('consider_websocket_secure', false)
|
2023-04-13 16:22:03 +00:00
|
|
|
if (this.paths.certs) {
|
|
|
|
this.global.set('certificates', this.paths.certs)
|
|
|
|
}
|
2021-04-30 14:22:58 +00:00
|
|
|
|
2023-09-18 16:53:07 +00:00
|
|
|
this.muc.set('admins', [])
|
2021-04-30 14:22:58 +00:00
|
|
|
this.muc.set('muc_room_locking', false)
|
|
|
|
this.muc.set('muc_tombstones', false)
|
|
|
|
this.muc.set('muc_room_default_language', 'en')
|
2021-05-02 12:35:58 +00:00
|
|
|
this.muc.set('muc_room_default_public', false)
|
2021-04-30 14:22:58 +00:00
|
|
|
this.muc.set('muc_room_default_persistent', false)
|
|
|
|
this.muc.set('muc_room_default_members_only', false)
|
|
|
|
this.muc.set('muc_room_default_moderated', false)
|
|
|
|
this.muc.set('muc_room_default_public_jids', false)
|
|
|
|
this.muc.set('muc_room_default_change_subject', false)
|
|
|
|
this.muc.set('muc_room_default_history_length', 20)
|
2024-02-13 10:26:29 +00:00
|
|
|
|
|
|
|
this.muc.add('modules_enabled', 'muc_slow_mode')
|
2024-06-25 07:59:46 +00:00
|
|
|
this.muc.add('slow_mode_duration_form_position', 120)
|
|
|
|
|
2024-05-01 14:23:40 +00:00
|
|
|
this.muc.add('modules_enabled', 'pubsub_peertubelivechat')
|
2024-06-20 14:46:14 +00:00
|
|
|
this.muc.add('modules_enabled', 'muc_peertubelivechat_roles')
|
2024-06-25 07:59:46 +00:00
|
|
|
|
|
|
|
this.muc.add('modules_enabled', 'muc_peertubelivechat_terms')
|
|
|
|
this.muc.set('muc_terms_service_nickname', 'Peertube')
|
|
|
|
if (chatTerms) {
|
2024-06-25 09:28:46 +00:00
|
|
|
this.muc.set('muc_terms_global', new ConfigEntryValueMultiLineString(chatTerms))
|
2024-06-25 07:59:46 +00:00
|
|
|
}
|
2021-04-30 14:22:58 +00:00
|
|
|
}
|
|
|
|
|
2023-09-22 16:17:54 +00:00
|
|
|
useAnonymous (autoBanIP: boolean): void {
|
2022-04-11 16:12:12 +00:00
|
|
|
this.anon = new ProsodyConfigVirtualHost('anon.' + this.prosodyDomain)
|
|
|
|
this.anon.set('authentication', 'anonymous')
|
|
|
|
this.anon.set('modules_enabled', ['ping'])
|
2024-02-01 14:20:52 +00:00
|
|
|
this.anon.set('modules_disabled', [
|
|
|
|
'carbons' // carbon make no sense for anonymous users, they can't have multiple windows
|
|
|
|
])
|
2023-09-22 16:17:54 +00:00
|
|
|
if (autoBanIP) {
|
|
|
|
this.anon.add('modules_enabled', 'muc_ban_ip')
|
|
|
|
}
|
2022-04-11 16:12:12 +00:00
|
|
|
}
|
|
|
|
|
2024-04-17 14:35:26 +00:00
|
|
|
/**
|
|
|
|
* Activates the virtual host for external account authentication (OpenID Connect, ...)
|
|
|
|
*/
|
|
|
|
useExternal (apikey: string): void {
|
|
|
|
this.external = new ProsodyConfigVirtualHost('external.' + this.prosodyDomain)
|
|
|
|
this.external.set('modules_enabled', [
|
|
|
|
'ping',
|
|
|
|
'http',
|
2024-04-18 16:25:14 +00:00
|
|
|
'vcard',
|
2024-04-17 14:35:26 +00:00
|
|
|
'http_peertubelivechat_manage_users'
|
|
|
|
])
|
|
|
|
this.external.set('peertubelivechat_manage_users_apikey', apikey)
|
|
|
|
}
|
|
|
|
|
2021-05-03 18:37:23 +00:00
|
|
|
useHttpAuthentication (url: string): void {
|
2021-05-06 11:31:55 +00:00
|
|
|
this.authenticated = new ProsodyConfigVirtualHost(this.prosodyDomain)
|
2021-05-03 18:37:23 +00:00
|
|
|
|
|
|
|
this.authenticated.set('authentication', 'http')
|
2023-04-11 15:07:43 +00:00
|
|
|
this.authenticated.set('modules_enabled', ['ping'])
|
2021-05-03 18:37:23 +00:00
|
|
|
|
|
|
|
this.authenticated.set('http_auth_url', url)
|
|
|
|
}
|
|
|
|
|
2023-09-19 13:54:56 +00:00
|
|
|
/**
|
|
|
|
* Activate BOSH (and optionnaly Websocket).
|
|
|
|
* @param prosodyDomain prosody domain
|
|
|
|
* @param port port to use for BOSH and Websocket interfaces
|
|
|
|
* @param publicServerUrl public server url
|
|
|
|
* @param useWS activate Websocket or not
|
|
|
|
* @param multiplexing activate multiplexing on port. Note: it will only listen on localhost interfaces.
|
|
|
|
*/
|
|
|
|
usePeertubeBoshAndWebsocket (
|
|
|
|
prosodyDomain: string,
|
|
|
|
port: string,
|
|
|
|
publicServerUrl: string,
|
|
|
|
useWS: boolean,
|
|
|
|
multiplexing: boolean
|
|
|
|
): void {
|
|
|
|
// Note: don't activate other http_interface or https_interfaces than localhost.
|
|
|
|
// Elsewhere it would be a security issue.
|
2021-04-30 14:22:58 +00:00
|
|
|
this.global.set('c2s_require_encryption', false)
|
|
|
|
this.global.set('interfaces', ['127.0.0.1', '::1'])
|
|
|
|
this.global.set('c2s_ports', [])
|
|
|
|
this.global.set('c2s_interfaces', ['127.0.0.1', '::1'])
|
|
|
|
this.global.set('s2s_ports', [])
|
|
|
|
this.global.set('s2s_interfaces', ['127.0.0.1', '::1'])
|
2023-09-19 13:54:56 +00:00
|
|
|
if (!multiplexing) {
|
|
|
|
this.global.set('http_ports', [port])
|
|
|
|
} else {
|
|
|
|
// Note: don't activate other http_interface or https_interfaces than localhost.
|
|
|
|
// Elsewhere it would be a security issue.
|
|
|
|
this.global.add('modules_enabled', 'net_multiplex')
|
|
|
|
this.global.set('ports', [port])
|
|
|
|
// FIXME: this generates Prosody error logs saying that BOSH/Websocket won't work... even if it is not true.
|
|
|
|
this.global.set('http_ports', [])
|
|
|
|
}
|
2021-04-30 14:22:58 +00:00
|
|
|
this.global.set('http_interfaces', ['127.0.0.1', '::1'])
|
|
|
|
this.global.set('https_ports', [])
|
|
|
|
this.global.set('https_interfaces', ['127.0.0.1', '::1'])
|
2023-04-11 15:07:43 +00:00
|
|
|
this.global.set('trusted_proxies', ['127.0.0.1', '::1'])
|
2021-04-30 14:22:58 +00:00
|
|
|
|
|
|
|
this.global.set('consider_bosh_secure', true)
|
2022-10-13 16:56:00 +00:00
|
|
|
if (useWS) {
|
|
|
|
this.global.set('consider_websocket_secure', true)
|
2022-11-01 10:58:02 +00:00
|
|
|
// c2s_close_timeout must be set accordingly with ConverseJS ping_interval (25s) and nginx timeout (30s)
|
|
|
|
this.global.set('c2s_close_timeout', 29)
|
2021-04-30 14:22:58 +00:00
|
|
|
|
2022-10-13 16:56:00 +00:00
|
|
|
// This line seems to be required by Prosody, otherwise it rejects websocket...
|
2023-04-11 15:07:43 +00:00
|
|
|
// this.global.set('cross_domain_websocket', [publicServerUrl]) No more needed with Prosody 0.12
|
2022-10-13 16:56:00 +00:00
|
|
|
}
|
2022-08-25 11:44:35 +00:00
|
|
|
|
2022-04-11 16:12:12 +00:00
|
|
|
if (this.anon) {
|
|
|
|
this.anon.set('allow_anonymous_s2s', false)
|
|
|
|
this.anon.add('modules_enabled', 'http')
|
|
|
|
this.anon.add('modules_enabled', 'bosh')
|
2022-10-13 16:56:00 +00:00
|
|
|
if (useWS) {
|
|
|
|
this.anon.add('modules_enabled', 'websocket')
|
|
|
|
}
|
2022-04-11 16:12:12 +00:00
|
|
|
this.anon.set('http_host', prosodyDomain)
|
|
|
|
this.anon.set('http_external_url', 'http://' + prosodyDomain)
|
|
|
|
}
|
2021-04-30 14:22:58 +00:00
|
|
|
|
|
|
|
this.muc.set('restrict_room_creation', 'local')
|
2021-07-06 09:26:37 +00:00
|
|
|
this.muc.set('http_host', prosodyDomain)
|
|
|
|
this.muc.set('http_external_url', 'http://' + prosodyDomain)
|
2021-05-03 18:37:23 +00:00
|
|
|
|
|
|
|
if (this.authenticated) {
|
|
|
|
this.authenticated.set('allow_anonymous_s2s', false)
|
|
|
|
this.authenticated.add('modules_enabled', 'http')
|
|
|
|
this.authenticated.add('modules_enabled', 'bosh')
|
2022-10-13 16:56:00 +00:00
|
|
|
if (useWS) {
|
|
|
|
this.authenticated.add('modules_enabled', 'websocket')
|
|
|
|
}
|
2021-05-06 11:31:55 +00:00
|
|
|
this.authenticated.set('http_host', prosodyDomain)
|
|
|
|
this.authenticated.set('http_external_url', 'http://' + prosodyDomain)
|
2021-05-03 18:37:23 +00:00
|
|
|
}
|
2024-04-17 14:35:26 +00:00
|
|
|
|
|
|
|
if (this.external) {
|
|
|
|
this.external.set('allow_anonymous_s2s', false)
|
|
|
|
this.external.add('modules_enabled', 'http')
|
|
|
|
this.external.add('modules_enabled', 'bosh')
|
|
|
|
if (useWS) {
|
|
|
|
this.external.add('modules_enabled', 'websocket')
|
|
|
|
}
|
|
|
|
this.external.set('http_host', prosodyDomain)
|
|
|
|
this.external.set('http_external_url', 'http://' + prosodyDomain)
|
|
|
|
}
|
2021-04-30 14:22:58 +00:00
|
|
|
}
|
|
|
|
|
2024-05-27 14:32:40 +00:00
|
|
|
useC2S (c2sPort: string, c2sInterfaces: string[]): void {
|
2021-07-14 16:46:08 +00:00
|
|
|
this.global.set('c2s_ports', [c2sPort])
|
2024-05-27 14:32:40 +00:00
|
|
|
this.global.set('c2s_interfaces', c2sInterfaces)
|
2021-07-14 16:46:08 +00:00
|
|
|
}
|
|
|
|
|
2023-05-19 10:52:52 +00:00
|
|
|
useS2S (
|
|
|
|
s2sPort: string | null,
|
|
|
|
s2sInterfaces: string[] | null,
|
|
|
|
publicServerUrl: string,
|
|
|
|
serverInfosDir: string
|
|
|
|
): void {
|
|
|
|
if (s2sPort !== null) {
|
|
|
|
this.global.set('s2s_ports', [s2sPort])
|
|
|
|
} else {
|
|
|
|
this.global.set('s2s_ports', [])
|
|
|
|
}
|
|
|
|
if (s2sInterfaces !== null) {
|
|
|
|
this.global.set('s2s_interfaces', s2sInterfaces)
|
|
|
|
} else {
|
|
|
|
this.global.set('s2s_interfaces', [])
|
|
|
|
}
|
2023-04-10 17:01:41 +00:00
|
|
|
this.global.set('s2s_secure_auth', false)
|
2023-05-19 10:52:52 +00:00
|
|
|
this.global.remove('modules_disabled', 's2s')
|
|
|
|
this.global.add('modules_enabled', 's2s')
|
2023-04-11 15:07:43 +00:00
|
|
|
this.global.add('modules_enabled', 'tls') // required for s2s and co
|
2023-05-19 10:52:52 +00:00
|
|
|
|
|
|
|
this.global.add('modules_enabled', 's2s_peertubelivechat')
|
|
|
|
this.global.set('peertubelivechat_server_infos_path', serverInfosDir)
|
|
|
|
this.global.set('peertubelivechat_instance_url', publicServerUrl)
|
|
|
|
|
|
|
|
this.global.add('modules_enabled', 'websocket_s2s_peertubelivechat')
|
2023-05-25 15:30:53 +00:00
|
|
|
// Nginx closes the websockets connection after a timeout. Seems the default is 60s.
|
|
|
|
// So we will ping on outgoing websocket s2s connection every 55s.
|
|
|
|
this.global.set('websocket_s2s_ping_interval', 55)
|
2023-05-22 12:37:08 +00:00
|
|
|
// FIXME: seems to be necessary to add the module on the muc host, so that dialback can trigger route/remote.
|
|
|
|
this.muc.add('modules_enabled', 'websocket_s2s_peertubelivechat')
|
2023-05-19 10:52:52 +00:00
|
|
|
|
2023-06-01 11:06:59 +00:00
|
|
|
// Using direct S2S for outgoing connection can be an issue, if the local instance dont allow incomming S2S.
|
|
|
|
// Indeed, the remote instance will not necessarely be able to discover the Websocket Endpoint.
|
|
|
|
// To be sure the remote instance knows the websocket endpoint, we must use Websocket for the firt outgoing connect.
|
|
|
|
// So, we will add a parameter for mod_s2s_peertubelivechat, to tell him not to use outgoint s2s connection.
|
|
|
|
this.global.set('s2s_peertubelivechat_no_outgoing_directs2s_to_peertube', s2sPort === null)
|
|
|
|
|
2023-04-10 17:01:41 +00:00
|
|
|
this.muc.add('modules_enabled', 'dialback') // This allows s2s connections without certicicates!
|
2023-05-19 10:52:52 +00:00
|
|
|
this.authenticated?.add('modules_enabled', 'dialback') // This allows s2s connections without certicicates!
|
2024-04-18 13:42:06 +00:00
|
|
|
this.external?.add('modules_enabled', 'dialback') // same.
|
2023-04-07 16:27:15 +00:00
|
|
|
}
|
|
|
|
|
2023-08-10 12:45:04 +00:00
|
|
|
useExternalComponents (
|
|
|
|
componentsPort: string,
|
|
|
|
componentsInterfaces: string[] | null,
|
|
|
|
components: ExternalComponent[]
|
|
|
|
): void {
|
2021-12-11 18:09:01 +00:00
|
|
|
this.global.set('component_ports', [componentsPort])
|
2023-08-10 12:45:04 +00:00
|
|
|
if (componentsInterfaces !== null) {
|
|
|
|
this.global.set('component_interfaces', componentsInterfaces)
|
|
|
|
} else {
|
|
|
|
this.global.set('component_interfaces', [])
|
|
|
|
}
|
2021-12-11 18:09:01 +00:00
|
|
|
|
|
|
|
for (const component of components) {
|
|
|
|
const c = new ProsodyConfigComponent(component.name)
|
|
|
|
c.set('component_secret', component.secret)
|
2022-11-01 10:23:34 +00:00
|
|
|
c.set('disco_hidden', true)
|
2021-12-11 18:09:01 +00:00
|
|
|
this.externalComponents.push(c)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-02 13:22:08 +00:00
|
|
|
useMucHttpDefault (url: string): void {
|
2021-04-30 14:22:58 +00:00
|
|
|
this.muc.add('modules_enabled', 'muc_http_defaults')
|
|
|
|
this.muc.add('muc_create_api_url', url)
|
2021-05-02 14:55:01 +00:00
|
|
|
|
|
|
|
// restrict_room_creation: we can override the 'local' value.
|
|
|
|
// Indeed, when muc_http_default is used, room creation will be managed by api.
|
|
|
|
this.muc.set('restrict_room_creation', false)
|
2021-04-30 14:22:58 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 14:10:57 +00:00
|
|
|
/**
|
|
|
|
* Calling this method makes Prosody use mod_muc_mam to store rooms history.
|
2021-12-01 11:57:15 +00:00
|
|
|
* @param logByDefault: if the room content should be archived by default.
|
|
|
|
* @param logExpiration: how long the server must store messages. See https://prosody.im/doc/modules/mod_muc_mam
|
2021-05-11 14:10:57 +00:00
|
|
|
*/
|
2021-12-01 11:57:15 +00:00
|
|
|
useMam (logByDefault: boolean, logExpiration: ConfigLogExpiration): void {
|
2021-05-11 14:10:57 +00:00
|
|
|
this.muc.add('modules_enabled', 'muc_mam')
|
|
|
|
|
2021-12-01 11:57:15 +00:00
|
|
|
this.muc.set('muc_log_by_default', !!logByDefault)
|
2021-05-11 14:10:57 +00:00
|
|
|
this.muc.set('muc_log_presences', true)
|
2021-12-01 11:57:15 +00:00
|
|
|
this.muc.set('log_all_rooms', false)
|
|
|
|
this.muc.set('muc_log_expires_after', logExpiration.value)
|
|
|
|
const defaultCleanupInterval = 4 * 60 * 60
|
|
|
|
if (logExpiration.type === 'seconds' && logExpiration.seconds && logExpiration.seconds < defaultCleanupInterval) {
|
|
|
|
// if the log expiration is less than the default cleanup interval, we have to decrease it.
|
|
|
|
this.muc.set('muc_log_cleanup_interval', logExpiration.seconds)
|
|
|
|
} else {
|
|
|
|
this.muc.set('muc_log_cleanup_interval', defaultCleanupInterval)
|
|
|
|
}
|
2021-05-11 14:49:49 +00:00
|
|
|
|
|
|
|
// We can also use mod_muc_moderation
|
2023-08-07 08:19:42 +00:00
|
|
|
// NB: Prosody has a partial support of this feature in combination with «internal» storage
|
2022-11-18 16:06:53 +00:00
|
|
|
// (Requires the `set` function in mod_storage_internal).
|
|
|
|
// This was fixed in Prosody 0.12.x.
|
2021-05-11 14:49:49 +00:00
|
|
|
this.muc.add('modules_enabled', 'muc_moderation')
|
2021-04-30 14:22:58 +00:00
|
|
|
}
|
|
|
|
|
2021-05-18 16:29:17 +00:00
|
|
|
/**
|
|
|
|
* Rooms will be persistent by default (they will not be deleted if no participant).
|
|
|
|
*/
|
|
|
|
useDefaultPersistent (): void {
|
|
|
|
this.muc.set('muc_room_default_persistent', true)
|
|
|
|
}
|
|
|
|
|
2024-03-07 15:22:14 +00:00
|
|
|
useManageRoomsApi (apikey: string): void {
|
|
|
|
this.muc.add('modules_enabled', 'http_peertubelivechat_manage_rooms')
|
|
|
|
this.muc.set('peertubelivechat_manage_rooms_apikey', apikey)
|
2021-06-12 01:52:45 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 10:57:24 +00:00
|
|
|
useTestModule (prosodyApikey: string, apiurl: string): void {
|
2021-07-20 00:52:58 +00:00
|
|
|
this.muc.add('modules_enabled', 'http_peertubelivechat_test')
|
|
|
|
this.muc.set('peertubelivechat_test_apikey', prosodyApikey)
|
|
|
|
this.muc.set('peertubelivechat_test_peertube_api_url', apiurl)
|
2021-06-22 08:26:45 +00:00
|
|
|
}
|
|
|
|
|
2022-01-05 17:53:44 +00:00
|
|
|
usePeertubeVCards (peertubeUrl: string): void {
|
|
|
|
if (this.authenticated) {
|
|
|
|
this.authenticated.add('modules_enabled', 'vcard_peertubelivechat')
|
|
|
|
this.authenticated.set('peertubelivechat_vcard_peertube_url', peertubeUrl)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-25 09:20:46 +00:00
|
|
|
useAnonymousRandomVCards (avatarPath: string, avatarFiles: string[]): void {
|
2022-01-06 04:30:55 +00:00
|
|
|
if (this.anon) {
|
|
|
|
this.anon.add('modules_enabled', 'random_vcard_peertubelivechat')
|
|
|
|
this.anon.set('peertubelivechat_random_vcard_avatars_path', avatarPath)
|
2023-09-25 09:20:46 +00:00
|
|
|
this.anon.set('peertubelivechat_random_vcard_avatars_files', avatarFiles)
|
2022-01-06 04:30:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-18 16:53:07 +00:00
|
|
|
/**
|
|
|
|
* Enable the bots virtualhost.
|
|
|
|
*/
|
2023-09-25 09:20:46 +00:00
|
|
|
useBotsVirtualHost (botAvatarPath: string, botAvatarFiles: string[]): void {
|
2023-09-18 16:53:07 +00:00
|
|
|
this.bot = new ProsodyConfigVirtualHost('bot.' + this.prosodyDomain)
|
2023-09-19 15:55:37 +00:00
|
|
|
this.bot.set('modules_enabled', ['ping'])
|
|
|
|
this.bot.set('authentication', 'peertubelivechat_bot')
|
2023-09-19 13:54:56 +00:00
|
|
|
|
2023-09-25 09:20:46 +00:00
|
|
|
// For now, just using random_vcard_peertubelivechat to set bot avatar
|
|
|
|
this.bot.add('modules_enabled', 'random_vcard_peertubelivechat')
|
|
|
|
this.bot.set('peertubelivechat_random_vcard_avatars_path', botAvatarPath)
|
|
|
|
this.bot.set('peertubelivechat_random_vcard_avatars_files', botAvatarFiles)
|
|
|
|
|
2023-09-19 16:02:57 +00:00
|
|
|
// Adding the moderation bot as admin to the muc component.
|
|
|
|
this.muc.add('admins', BotConfiguration.singleton().moderationBotJID())
|
|
|
|
|
2023-09-19 13:54:56 +00:00
|
|
|
const configurationPaths = BotConfiguration.singleton().configurationPaths()
|
|
|
|
if (configurationPaths.moderation?.globalDir) {
|
|
|
|
this.bot.set('livechat_bot_conf_folder', configurationPaths.moderation.globalDir)
|
|
|
|
}
|
2023-09-18 16:53:07 +00:00
|
|
|
}
|
|
|
|
|
2024-02-29 14:58:41 +00:00
|
|
|
addMucAdmins (jids: string[]): void {
|
|
|
|
for (const jid of jids) {
|
|
|
|
this.muc.add('admins', jid)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-30 14:22:58 +00:00
|
|
|
setLog (level: ProsodyLogLevel, syslog?: ProsodyLogLevel[]): void {
|
|
|
|
let log = ''
|
|
|
|
log += 'log = {\n'
|
2021-05-12 09:48:38 +00:00
|
|
|
if (level !== 'error') {
|
|
|
|
log += ' ' + level + ' = ' + writeValue(this.paths.log)
|
|
|
|
}
|
|
|
|
// always log error level in a separate file.
|
2021-04-30 14:22:58 +00:00
|
|
|
log += ' error = ' + writeValue(this.paths.error)
|
|
|
|
if (syslog) {
|
|
|
|
log += ' { to = "syslog"; levels = ' + writeValue(syslog) + ' };\n'
|
|
|
|
}
|
|
|
|
log += '\n};\n'
|
|
|
|
this.log = log
|
|
|
|
}
|
|
|
|
|
|
|
|
public write (): string {
|
|
|
|
let content = ''
|
|
|
|
content += this.global.write()
|
|
|
|
content += this.log + '\n'
|
|
|
|
content += '\n\n'
|
2021-05-03 18:37:23 +00:00
|
|
|
if (this.authenticated) {
|
|
|
|
content += this.authenticated.write()
|
|
|
|
content += '\n\n'
|
|
|
|
}
|
2022-04-11 16:12:12 +00:00
|
|
|
if (this.anon) {
|
|
|
|
content += this.anon.write()
|
|
|
|
content += '\n\n'
|
|
|
|
}
|
2023-09-18 16:53:07 +00:00
|
|
|
if (this.bot) {
|
|
|
|
content += this.bot.write()
|
|
|
|
content += '\n\n'
|
|
|
|
}
|
2024-04-17 14:35:26 +00:00
|
|
|
if (this.external) {
|
|
|
|
content += this.external.write()
|
|
|
|
content += '\n\n'
|
|
|
|
}
|
2021-04-30 14:22:58 +00:00
|
|
|
content += this.muc.write()
|
|
|
|
content += '\n\n'
|
2021-12-11 18:09:01 +00:00
|
|
|
for (const externalComponent of this.externalComponents) {
|
|
|
|
content += '\n\n'
|
|
|
|
content += externalComponent.write()
|
|
|
|
content += '\n\n'
|
|
|
|
}
|
2021-04-30 14:22:58 +00:00
|
|
|
return content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export {
|
2021-05-12 09:48:38 +00:00
|
|
|
ProsodyLogLevel,
|
2021-12-01 11:57:15 +00:00
|
|
|
ProsodyConfigContent,
|
|
|
|
ConfigLogExpiration
|
2021-04-30 14:22:58 +00:00
|
|
|
}
|