2022-01-11 00:29:33 +00:00
|
|
|
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
2023-09-18 16:53:07 +00:00
|
|
|
import type { Config as XMPPBotConfig } from 'xmppjs-chat-bot'
|
2021-12-11 18:09:01 +00:00
|
|
|
import type { ProsodyLogLevel } from './config/content'
|
2021-04-12 18:52:21 +00:00
|
|
|
import * as fs from 'fs'
|
2021-04-13 15:13:41 +00:00
|
|
|
import * as path from 'path'
|
2022-10-13 16:56:00 +00:00
|
|
|
import { getBaseRouterRoute, RegisterServerOptionsV5 } from '../helpers'
|
2021-04-30 14:22:58 +00:00
|
|
|
import { ProsodyFilePaths } from './config/paths'
|
2021-12-01 11:57:15 +00:00
|
|
|
import { ConfigLogExpiration, ProsodyConfigContent } from './config/content'
|
2021-05-06 11:31:55 +00:00
|
|
|
import { getProsodyDomain } from './config/domain'
|
2021-12-11 16:12:04 +00:00
|
|
|
import { getAPIKey } from '../apikey'
|
2021-12-11 18:09:01 +00:00
|
|
|
import { parseExternalComponents } from './config/components'
|
2023-05-19 10:52:52 +00:00
|
|
|
import { getRemoteServerInfosDir } from '../federation/storage'
|
2023-09-18 16:53:07 +00:00
|
|
|
import { BotConfiguration } from '../configuration/bot'
|
2021-04-12 18:52:21 +00:00
|
|
|
|
2021-06-02 10:41:28 +00:00
|
|
|
async function getWorkingDir (options: RegisterServerOptions): Promise<string> {
|
2021-05-11 13:37:34 +00:00
|
|
|
const peertubeHelpers = options.peertubeHelpers
|
|
|
|
const logger = peertubeHelpers.logger
|
|
|
|
logger.debug('Calling getWorkingDir')
|
|
|
|
|
2021-06-02 13:48:56 +00:00
|
|
|
if (!peertubeHelpers.plugin) {
|
|
|
|
throw new Error('Missing peertubeHelpers.plugin, have you the correct Peertube version?')
|
2021-05-11 13:37:34 +00:00
|
|
|
}
|
2021-06-02 10:41:28 +00:00
|
|
|
const dir = path.resolve(peertubeHelpers.plugin.getDataDirectoryPath(), 'prosody')
|
|
|
|
logger.debug('getWorkingDir will return the dir ' + dir)
|
|
|
|
return dir
|
2021-05-11 13:37:34 +00:00
|
|
|
}
|
|
|
|
|
2021-04-13 15:13:41 +00:00
|
|
|
async function getProsodyFilePaths (options: RegisterServerOptions): Promise<ProsodyFilePaths> {
|
2021-04-14 15:10:22 +00:00
|
|
|
const logger = options.peertubeHelpers.logger
|
|
|
|
logger.debug('Calling getProsodyFilePaths')
|
|
|
|
|
2021-06-02 10:41:28 +00:00
|
|
|
const dir = await getWorkingDir(options)
|
2023-04-13 16:22:03 +00:00
|
|
|
const settings = await options.settingsManager.getSettings([
|
|
|
|
'use-system-prosody', 'prosody-room-allow-s2s', 'prosody-certificates-dir'
|
|
|
|
])
|
2022-11-14 15:54:08 +00:00
|
|
|
let exec
|
2022-12-12 18:17:43 +00:00
|
|
|
let execArgs: string[] = []
|
2022-11-14 15:54:08 +00:00
|
|
|
let execCtl
|
2022-12-12 18:17:43 +00:00
|
|
|
let execCtlArgs: string[] = []
|
2022-11-14 15:54:08 +00:00
|
|
|
let appImageToExtract
|
2022-11-15 15:30:24 +00:00
|
|
|
|
|
|
|
// this one is always needed (must create the directory on startup)
|
|
|
|
const appImageExtractPath = path.resolve(dir, '..', 'prosodyAppImage')
|
|
|
|
|
2022-11-14 15:54:08 +00:00
|
|
|
if (settings['use-system-prosody']) {
|
|
|
|
exec = 'prosody'
|
|
|
|
execCtl = 'prosodyctl'
|
|
|
|
} else {
|
2022-12-12 18:17:43 +00:00
|
|
|
// const arch = process.arch
|
|
|
|
// if (arch === 'arm' || arch === 'arm64') {
|
|
|
|
// logger.info('Node process.arch is ' + arch + ', we will be using the aarch64 Prosody AppImage')
|
|
|
|
// appImageToExtract = path.resolve(__dirname, '../../prosody/livechat-prosody-aarch64.AppImage')
|
|
|
|
// } else {
|
|
|
|
// appImageToExtract = path.resolve(__dirname, '../../prosody/livechat-prosody-x86_64.AppImage')
|
|
|
|
// }
|
2023-05-31 16:13:35 +00:00
|
|
|
if (process.arch === 'x64' || process.arch === 'x86_64') {
|
2022-12-12 18:17:43 +00:00
|
|
|
logger.debug('Node process.arch is ' + process.arch + ', we will be using the x86_64 Prosody AppImage')
|
2022-11-22 10:35:38 +00:00
|
|
|
appImageToExtract = path.resolve(__dirname, '../../prosody/livechat-prosody-x86_64.AppImage')
|
2022-12-12 18:17:43 +00:00
|
|
|
exec = path.resolve(appImageExtractPath, 'squashfs-root/AppRun')
|
|
|
|
execArgs = ['prosody']
|
|
|
|
execCtl = exec
|
|
|
|
execCtlArgs = ['prosodyctl']
|
2023-05-31 16:13:35 +00:00
|
|
|
} else if (process.arch === 'arm64') {
|
|
|
|
logger.debug('Node process.arch is ' + process.arch + ', we will be using the aarch64 Prosody AppImage')
|
|
|
|
appImageToExtract = path.resolve(__dirname, '../../prosody/livechat-prosody-aarch64.AppImage')
|
|
|
|
exec = path.resolve(appImageExtractPath, 'squashfs-root/AppRun')
|
|
|
|
execArgs = ['prosody']
|
|
|
|
execCtl = exec
|
|
|
|
execCtlArgs = ['prosodyctl']
|
|
|
|
} else {
|
|
|
|
logger.info('Node process.arch is ' + process.arch + ', cant use the Prosody AppImage')
|
2022-11-22 10:35:38 +00:00
|
|
|
}
|
2022-11-14 15:54:08 +00:00
|
|
|
}
|
2022-11-15 15:30:24 +00:00
|
|
|
|
2023-04-13 16:22:03 +00:00
|
|
|
let certsDir: string | undefined = path.resolve(dir, 'certs')
|
|
|
|
let certsDirIsCustom = false
|
2023-05-19 10:52:52 +00:00
|
|
|
if (settings['prosody-room-allow-s2s'] && (settings['prosody-certificates-dir'] as string ?? '') !== '') {
|
|
|
|
if (!fs.statSync(settings['prosody-certificates-dir'] as string).isDirectory()) {
|
|
|
|
// We can throw an exception here...
|
|
|
|
// Because if the user input a wrong directory, the plugin will not register,
|
|
|
|
// and he will never be able to fix the conf
|
|
|
|
logger.error('Certificate directory does not exist or is not a directory')
|
|
|
|
certsDir = undefined
|
2023-04-13 16:22:03 +00:00
|
|
|
} else {
|
2023-05-19 10:52:52 +00:00
|
|
|
certsDir = settings['prosody-certificates-dir'] as string
|
2023-04-13 16:22:03 +00:00
|
|
|
}
|
2023-05-19 10:52:52 +00:00
|
|
|
certsDirIsCustom = true
|
|
|
|
} else {
|
|
|
|
// In this case we are generating and using self signed certificates
|
|
|
|
|
|
|
|
// Note: when using prosodyctl to generate self-signed certificates,
|
|
|
|
// there are wrongly generated in the data dir.
|
|
|
|
// So we will use this dir as the certs dir.
|
|
|
|
certsDir = path.resolve(dir, 'data')
|
2023-04-13 11:01:48 +00:00
|
|
|
}
|
|
|
|
|
2023-09-25 09:20:46 +00:00
|
|
|
const avatarsDir = path.resolve(__dirname, '../../avatars')
|
|
|
|
const avatarsFiles = await _listAvatars(avatarsDir)
|
|
|
|
const botAvatarsDir = path.resolve(__dirname, '../../bot_avatars')
|
|
|
|
const botAvatarsFiles = await _listAvatars(botAvatarsDir)
|
|
|
|
|
2021-04-13 15:13:41 +00:00
|
|
|
return {
|
2021-04-14 13:26:00 +00:00
|
|
|
dir: dir,
|
2021-04-13 15:13:41 +00:00
|
|
|
pid: path.resolve(dir, 'prosody.pid'),
|
|
|
|
error: path.resolve(dir, 'prosody.err'),
|
|
|
|
log: path.resolve(dir, 'prosody.log'),
|
2021-04-16 12:26:21 +00:00
|
|
|
config: path.resolve(dir, 'prosody.cfg.lua'),
|
2021-04-29 14:50:30 +00:00
|
|
|
data: path.resolve(dir, 'data'),
|
2023-04-13 11:01:48 +00:00
|
|
|
certs: certsDir,
|
2023-04-13 16:22:03 +00:00
|
|
|
certsDirIsCustom,
|
2022-01-06 04:30:55 +00:00
|
|
|
modules: path.resolve(__dirname, '../../prosody-modules'),
|
2023-09-25 09:20:46 +00:00
|
|
|
avatars: avatarsDir,
|
|
|
|
avatarsFiles,
|
|
|
|
botAvatars: botAvatarsDir,
|
|
|
|
botAvatarsFiles,
|
2022-11-14 15:54:08 +00:00
|
|
|
exec,
|
|
|
|
execArgs,
|
|
|
|
execCtl,
|
|
|
|
execCtlArgs,
|
2022-11-15 15:30:24 +00:00
|
|
|
appImageToExtract,
|
|
|
|
appImageExtractPath
|
2021-04-13 15:13:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-13 16:22:03 +00:00
|
|
|
type ProsodyConfigCertificates = false | 'generate-self-signed' | 'use-from-dir'
|
2023-04-13 15:00:34 +00:00
|
|
|
|
2021-12-11 16:12:04 +00:00
|
|
|
interface ProsodyConfig {
|
2021-04-15 10:17:08 +00:00
|
|
|
content: string
|
2021-12-11 16:12:04 +00:00
|
|
|
paths: ProsodyFilePaths
|
|
|
|
host: string
|
|
|
|
port: string
|
|
|
|
baseApiUrl: string
|
|
|
|
roomType: 'video' | 'channel'
|
|
|
|
logByDefault: boolean
|
|
|
|
logExpiration: ConfigLogExpiration
|
2021-12-11 18:09:01 +00:00
|
|
|
valuesToHideInDiagnostic: Map<string, string>
|
2023-04-13 15:00:34 +00:00
|
|
|
certificates: ProsodyConfigCertificates
|
2023-09-18 16:53:07 +00:00
|
|
|
bots: {
|
|
|
|
moderation?: XMPPBotConfig
|
|
|
|
}
|
2021-04-15 10:17:08 +00:00
|
|
|
}
|
2022-10-13 16:56:00 +00:00
|
|
|
async function getProsodyConfig (options: RegisterServerOptionsV5): Promise<ProsodyConfig> {
|
2021-04-14 15:10:22 +00:00
|
|
|
const logger = options.peertubeHelpers.logger
|
2021-04-15 10:17:08 +00:00
|
|
|
logger.debug('Calling getProsodyConfig')
|
2021-04-14 15:10:22 +00:00
|
|
|
|
2021-12-07 09:29:20 +00:00
|
|
|
const settings = await options.settingsManager.getSettings([
|
|
|
|
'prosody-port',
|
|
|
|
'prosody-muc-log-by-default',
|
|
|
|
'prosody-muc-expiration',
|
|
|
|
'prosody-c2s',
|
2021-12-11 18:09:01 +00:00
|
|
|
'prosody-c2s-port',
|
2023-04-07 16:27:15 +00:00
|
|
|
'prosody-room-allow-s2s',
|
|
|
|
'prosody-s2s-port',
|
|
|
|
'prosody-s2s-interfaces',
|
2023-04-13 16:22:03 +00:00
|
|
|
'prosody-certificates-dir',
|
2021-12-07 09:29:20 +00:00
|
|
|
'prosody-room-type',
|
|
|
|
'prosody-peertube-uri',
|
2021-12-11 18:09:01 +00:00
|
|
|
'prosody-components',
|
|
|
|
'prosody-components-port',
|
2023-08-10 12:45:04 +00:00
|
|
|
'prosody-components-interfaces',
|
2022-04-11 16:12:12 +00:00
|
|
|
'prosody-components-list',
|
2023-05-19 10:52:52 +00:00
|
|
|
'chat-no-anonymous',
|
2023-09-22 16:17:54 +00:00
|
|
|
'auto-ban-anonymous-ip',
|
2023-09-18 16:53:07 +00:00
|
|
|
'federation-dont-publish-remotely',
|
|
|
|
'disable-channel-configuration'
|
2021-12-07 09:29:20 +00:00
|
|
|
])
|
|
|
|
|
2021-12-11 18:09:01 +00:00
|
|
|
const valuesToHideInDiagnostic = new Map<string, string>()
|
2021-12-07 09:29:20 +00:00
|
|
|
const port = (settings['prosody-port'] as string) || '52800'
|
2021-04-16 13:13:46 +00:00
|
|
|
if (!/^\d+$/.test(port)) {
|
|
|
|
throw new Error('Invalid port')
|
|
|
|
}
|
2021-12-07 09:29:20 +00:00
|
|
|
const logByDefault = (settings['prosody-muc-log-by-default'] as boolean) ?? true
|
2022-04-11 16:12:12 +00:00
|
|
|
const disableAnon = (settings['chat-no-anonymous'] as boolean) || false
|
2023-09-22 16:17:54 +00:00
|
|
|
const autoBanIP = (settings['auto-ban-anonymous-ip'] as boolean) || false
|
2021-12-07 09:29:20 +00:00
|
|
|
const logExpirationSetting = (settings['prosody-muc-expiration'] as string) ?? DEFAULTLOGEXPIRATION
|
2023-04-07 16:27:15 +00:00
|
|
|
const enableC2S = (settings['prosody-c2s'] as boolean) || false
|
2023-05-19 10:52:52 +00:00
|
|
|
// enableRoomS2S: room can be joined from remote XMPP servers (Peertube or not)
|
2023-04-07 16:27:15 +00:00
|
|
|
const enableRoomS2S = (settings['prosody-room-allow-s2s'] as boolean) || false
|
2021-12-13 20:51:00 +00:00
|
|
|
const enableComponents = (settings['prosody-components'] as boolean) || false
|
2021-05-06 11:31:55 +00:00
|
|
|
const prosodyDomain = await getProsodyDomain(options)
|
2021-04-13 15:13:41 +00:00
|
|
|
const paths = await getProsodyFilePaths(options)
|
2021-12-11 16:12:04 +00:00
|
|
|
const roomType = settings['prosody-room-type'] === 'channel' ? 'channel' : 'video'
|
2023-05-19 10:52:52 +00:00
|
|
|
// enableRemoteChatConnections: local users can communicate with external rooms
|
|
|
|
const enableRemoteChatConnections = !(settings['federation-dont-publish-remotely'] as boolean)
|
2023-04-13 15:00:34 +00:00
|
|
|
let certificates: ProsodyConfigCertificates = false
|
2023-09-19 13:54:56 +00:00
|
|
|
const useBots = !settings['disable-channel-configuration']
|
2023-09-18 16:53:07 +00:00
|
|
|
const bots: ProsodyConfig['bots'] = {}
|
2021-04-12 18:52:21 +00:00
|
|
|
|
2023-09-19 13:54:56 +00:00
|
|
|
// Note: for the bots to connect, we must allow multiplexing.
|
|
|
|
// This will be done on the http (BOSH/Websocket) port, as it only listen on localhost.
|
|
|
|
// TODO: to improve performance, try to avoid multiplexing, and find a better way for bots to connect.
|
|
|
|
const useMultiplexing = useBots
|
|
|
|
|
2021-05-05 15:06:19 +00:00
|
|
|
const apikey = await getAPIKey(options)
|
2021-12-11 18:09:01 +00:00
|
|
|
valuesToHideInDiagnostic.set('APIKey', apikey)
|
2021-12-07 09:50:28 +00:00
|
|
|
|
2023-05-19 10:52:52 +00:00
|
|
|
const publicServerUrl = options.peertubeHelpers.config.getWebserverUrl()
|
|
|
|
|
2022-01-05 17:53:44 +00:00
|
|
|
let basePeertubeUrl = settings['prosody-peertube-uri'] as string
|
2023-08-02 15:05:37 +00:00
|
|
|
if (basePeertubeUrl) {
|
|
|
|
logger.debug('basePeertubeUrl for internal API: using the settings value')
|
|
|
|
if (!/^https?:\/\/[a-z0-9.-_]+(?::\d+)?$/.test(basePeertubeUrl)) {
|
|
|
|
throw new Error('Invalid prosody-peertube-uri')
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!basePeertubeUrl && ('getServerListeningConfig' in options.peertubeHelpers.config)) {
|
|
|
|
// Peertube >=5.1 has getServerListeningConfig to get relevant information.
|
|
|
|
const listeningConfig = options.peertubeHelpers.config.getServerListeningConfig()
|
|
|
|
if (listeningConfig?.port) {
|
|
|
|
if (!listeningConfig.hostname || listeningConfig.hostname === '::') {
|
|
|
|
logger.debug(
|
|
|
|
'basePeertubeUrl for internal API: getServerListeningConfig.hostname==="' +
|
|
|
|
(listeningConfig.hostname ?? '') +
|
|
|
|
'", fallbacking on 127.0.0.1.'
|
|
|
|
)
|
|
|
|
basePeertubeUrl = `http://127.0.0.1:${listeningConfig.port}`
|
|
|
|
} else {
|
|
|
|
logger.debug('basePeertubeUrl for internal API: using getServerListeningConfig')
|
|
|
|
basePeertubeUrl = `http://${listeningConfig.hostname}:${listeningConfig.port}`
|
|
|
|
}
|
|
|
|
}
|
2021-06-22 11:23:01 +00:00
|
|
|
}
|
2022-01-05 17:53:44 +00:00
|
|
|
if (!basePeertubeUrl) {
|
2023-08-02 15:05:37 +00:00
|
|
|
// In still nothing, just using the public url (it will get througt nginx, but will work)
|
|
|
|
logger.debug('basePeertubeUrl for internal API: using public Url')
|
2023-05-19 10:52:52 +00:00
|
|
|
basePeertubeUrl = publicServerUrl
|
2021-06-22 11:23:01 +00:00
|
|
|
}
|
2022-01-05 17:53:44 +00:00
|
|
|
const baseApiUrl = basePeertubeUrl + getBaseRouterRoute(options) + 'api/'
|
2021-06-22 11:23:01 +00:00
|
|
|
|
2021-05-05 15:06:19 +00:00
|
|
|
const authApiUrl = baseApiUrl + 'user' // FIXME: should be protected by apikey, but mod_auth_http cant handle params
|
|
|
|
const roomApiUrl = baseApiUrl + 'room?apikey=' + apikey + '&jid={room.jid|jid_node}'
|
2021-06-22 10:57:24 +00:00
|
|
|
const testApiUrl = baseApiUrl + 'test?apikey=' + apikey
|
2021-04-12 18:52:21 +00:00
|
|
|
|
2021-05-06 11:31:55 +00:00
|
|
|
const config = new ProsodyConfigContent(paths, prosodyDomain)
|
2022-04-11 16:12:12 +00:00
|
|
|
if (!disableAnon) {
|
2023-09-22 16:17:54 +00:00
|
|
|
config.useAnonymous(autoBanIP)
|
2022-04-11 16:12:12 +00:00
|
|
|
}
|
2021-05-03 18:37:23 +00:00
|
|
|
config.useHttpAuthentication(authApiUrl)
|
2022-10-13 16:56:00 +00:00
|
|
|
const useWS = !!options.registerWebSocketRoute // this comes with Peertube >=5.0.0, and is a prerequisite to websocket
|
2023-09-19 13:54:56 +00:00
|
|
|
config.usePeertubeBoshAndWebsocket(prosodyDomain, port, publicServerUrl, useWS, useMultiplexing)
|
2021-04-30 14:22:58 +00:00
|
|
|
config.useMucHttpDefault(roomApiUrl)
|
2021-06-02 10:41:28 +00:00
|
|
|
|
2023-04-07 16:27:15 +00:00
|
|
|
if (enableC2S) {
|
2021-12-07 09:29:20 +00:00
|
|
|
const c2sPort = (settings['prosody-c2s-port'] as string) || '52822'
|
2021-07-14 16:46:08 +00:00
|
|
|
if (!/^\d+$/.test(c2sPort)) {
|
|
|
|
throw new Error('Invalid c2s port')
|
|
|
|
}
|
|
|
|
config.useC2S(c2sPort)
|
|
|
|
}
|
|
|
|
|
2021-12-11 18:09:01 +00:00
|
|
|
if (enableComponents) {
|
|
|
|
const componentsPort = (settings['prosody-components-port'] as string) || '53470'
|
|
|
|
if (!/^\d+$/.test(componentsPort)) {
|
|
|
|
throw new Error('Invalid external components port')
|
|
|
|
}
|
2023-08-10 12:45:04 +00:00
|
|
|
const componentsInterfaces = ((settings['prosody-components-interfaces'] as string) || '')
|
|
|
|
.split(',')
|
|
|
|
.map(s => s.trim())
|
|
|
|
// Check that there is no invalid values (to avoid injections):
|
|
|
|
componentsInterfaces.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 components interfaces')
|
|
|
|
})
|
2021-12-11 18:09:01 +00:00
|
|
|
const components = parseExternalComponents((settings['prosody-components-list'] as string) || '', prosodyDomain)
|
|
|
|
for (const component of components) {
|
|
|
|
valuesToHideInDiagnostic.set('Component ' + component.name + ' secret', component.secret)
|
|
|
|
}
|
2023-08-10 12:45:04 +00:00
|
|
|
config.useExternalComponents(componentsPort, componentsInterfaces, components)
|
2021-12-11 18:09:01 +00:00
|
|
|
}
|
|
|
|
|
2023-05-19 10:52:52 +00:00
|
|
|
if (enableRoomS2S || enableRemoteChatConnections) {
|
2023-04-13 15:00:34 +00:00
|
|
|
certificates = 'generate-self-signed'
|
2023-04-13 16:22:03 +00:00
|
|
|
if (config.paths.certsDirIsCustom) {
|
|
|
|
certificates = 'use-from-dir'
|
|
|
|
}
|
2023-05-19 10:52:52 +00:00
|
|
|
let s2sPort, s2sInterfaces
|
|
|
|
if (enableRoomS2S) {
|
|
|
|
s2sPort = (settings['prosody-s2s-port'] as string) || '5269'
|
|
|
|
if (!/^\d+$/.test(s2sPort)) {
|
|
|
|
throw new Error('Invalid s2s port')
|
|
|
|
}
|
|
|
|
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')
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
s2sPort = null
|
|
|
|
s2sInterfaces = null
|
2023-04-07 16:27:15 +00:00
|
|
|
}
|
2023-05-19 10:52:52 +00:00
|
|
|
config.useS2S(s2sPort, s2sInterfaces, publicServerUrl, getRemoteServerInfosDir(options))
|
2023-04-07 16:27:15 +00:00
|
|
|
}
|
|
|
|
|
2021-12-01 11:57:15 +00:00
|
|
|
const logExpiration = readLogExpiration(options, logExpirationSetting)
|
|
|
|
config.useMam(logByDefault, logExpiration)
|
2021-06-02 10:41:28 +00:00
|
|
|
// TODO: add a settings to choose?
|
|
|
|
config.useDefaultPersistent()
|
|
|
|
|
2021-06-12 01:52:45 +00:00
|
|
|
config.useListRoomsApi(apikey)
|
2022-01-05 17:53:44 +00:00
|
|
|
config.usePeertubeVCards(basePeertubeUrl)
|
2023-09-25 09:20:46 +00:00
|
|
|
config.useAnonymousRandomVCards(paths.avatars, paths.avatarsFiles)
|
2021-06-12 01:52:45 +00:00
|
|
|
|
2023-09-19 13:54:56 +00:00
|
|
|
if (useBots) {
|
2023-09-25 09:20:46 +00:00
|
|
|
config.useBotsVirtualHost(paths.botAvatars, paths.botAvatarsFiles)
|
2023-09-18 16:53:07 +00:00
|
|
|
bots.moderation = await BotConfiguration.singleton().getModerationBotGlobalConf()
|
2023-09-19 13:54:56 +00:00
|
|
|
if (bots.moderation?.connection?.password) {
|
|
|
|
valuesToHideInDiagnostic.set('BotPassword', bots.moderation.connection.password)
|
|
|
|
}
|
2023-09-18 16:53:07 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 10:57:24 +00:00
|
|
|
config.useTestModule(apikey, testApiUrl)
|
2021-06-22 08:26:45 +00:00
|
|
|
|
2021-05-12 09:48:38 +00:00
|
|
|
let logLevel: ProsodyLogLevel | undefined
|
|
|
|
if (logger.level && (typeof logger.level === 'string')) {
|
|
|
|
if (logger.level === 'error' || logger.level === 'info' || logger.level === 'debug') {
|
|
|
|
logLevel = logger.level
|
|
|
|
} else if (logger.level === 'warn' || logger.level === 'warning') {
|
|
|
|
// Should be 'warn', but just in case... (this value was buggy with peertube <= 3.2.0-rc1)
|
|
|
|
logLevel = 'warn'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (logLevel === undefined) {
|
|
|
|
logger.info('No log level found in Peertube, will use default "info" for Prosody')
|
|
|
|
logLevel = 'info'
|
|
|
|
}
|
|
|
|
config.setLog(logLevel)
|
2021-04-30 14:22:58 +00:00
|
|
|
const content = config.write()
|
2021-04-29 14:50:30 +00:00
|
|
|
|
2021-12-11 16:12:04 +00:00
|
|
|
return {
|
|
|
|
content,
|
2021-04-15 10:17:08 +00:00
|
|
|
paths,
|
2021-06-22 11:23:01 +00:00
|
|
|
port,
|
2021-07-20 00:52:58 +00:00
|
|
|
baseApiUrl,
|
2021-12-11 16:12:04 +00:00
|
|
|
host: prosodyDomain,
|
2021-12-01 11:57:15 +00:00
|
|
|
roomType,
|
|
|
|
logByDefault,
|
2021-12-07 09:29:20 +00:00
|
|
|
logExpiration,
|
2023-04-13 10:41:54 +00:00
|
|
|
valuesToHideInDiagnostic,
|
2023-09-18 16:53:07 +00:00
|
|
|
certificates,
|
|
|
|
bots
|
2021-12-11 16:12:04 +00:00
|
|
|
}
|
2021-04-12 18:52:21 +00:00
|
|
|
}
|
|
|
|
|
2021-04-15 10:17:08 +00:00
|
|
|
async function writeProsodyConfig (options: RegisterServerOptions): Promise<ProsodyConfig> {
|
2021-04-13 15:13:41 +00:00
|
|
|
const logger = options.peertubeHelpers.logger
|
2021-04-14 15:10:22 +00:00
|
|
|
logger.debug('Calling writeProsodyConfig')
|
|
|
|
|
|
|
|
logger.debug('Computing the Prosody config content')
|
2021-04-15 10:17:08 +00:00
|
|
|
const config = await getProsodyConfig(options)
|
2021-12-11 16:12:04 +00:00
|
|
|
const content = config.content
|
|
|
|
const fileName = config.paths.config
|
2021-04-14 15:10:22 +00:00
|
|
|
|
2021-12-11 16:12:04 +00:00
|
|
|
logger.info(`Writing prosody configuration file to ${fileName}`)
|
|
|
|
await fs.promises.writeFile(fileName, content)
|
|
|
|
logger.debug('Prosody configuration file writen')
|
2021-04-15 10:17:08 +00:00
|
|
|
|
|
|
|
return config
|
2021-04-13 15:13:41 +00:00
|
|
|
}
|
|
|
|
|
2021-12-01 11:57:15 +00:00
|
|
|
const DEFAULTLOGEXPIRATION = '1w'
|
|
|
|
const DEFAULTLOGEXPIRATIONTYPE = 'period'
|
|
|
|
function readLogExpiration (options: RegisterServerOptions, logExpiration: string): ConfigLogExpiration {
|
|
|
|
const logger = options.peertubeHelpers.logger
|
|
|
|
logExpiration = logExpiration?.trim()
|
|
|
|
if (logExpiration === 'never') {
|
|
|
|
return {
|
|
|
|
value: 'never',
|
|
|
|
type: 'never'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (/^\d+$/.test(logExpiration)) {
|
|
|
|
if (logExpiration === '0') {
|
|
|
|
logger.error('Invalid prosody-muc-expiration value, cannot be 0.')
|
|
|
|
return {
|
|
|
|
value: DEFAULTLOGEXPIRATION,
|
|
|
|
type: DEFAULTLOGEXPIRATIONTYPE,
|
|
|
|
error: '0 is not an acceptable value.'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
value: logExpiration,
|
|
|
|
type: 'seconds',
|
|
|
|
seconds: parseInt(logExpiration)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const matches = logExpiration.match(/^(\d+)([d|w|m|y])$/)
|
|
|
|
if (matches) {
|
|
|
|
const d = matches[1]
|
|
|
|
if (d === '0') {
|
|
|
|
logger.error(`Invalid prosody-muc-expiration value, cannot be ${logExpiration}.`)
|
|
|
|
return {
|
|
|
|
value: DEFAULTLOGEXPIRATION,
|
|
|
|
type: DEFAULTLOGEXPIRATIONTYPE,
|
|
|
|
error: '0 is not an acceptable value.'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
value: logExpiration,
|
|
|
|
type: 'period'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
logger.error(`Invalid prosody-muc-expiration value '${logExpiration}'.`)
|
|
|
|
return {
|
|
|
|
value: DEFAULTLOGEXPIRATION,
|
|
|
|
type: DEFAULTLOGEXPIRATIONTYPE,
|
|
|
|
error: `Invalid value '${logExpiration}'.`
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-11 16:12:04 +00:00
|
|
|
function getProsodyConfigContentForDiagnostic (config: ProsodyConfig, content?: string): string {
|
|
|
|
let r: string = content ?? config.content
|
2021-12-11 18:09:01 +00:00
|
|
|
for (const [key, value] of config.valuesToHideInDiagnostic.entries()) {
|
2021-12-11 16:12:04 +00:00
|
|
|
// replaceAll not available, using trick:
|
2021-12-11 18:09:01 +00:00
|
|
|
r = r.split(value).join(`***${key}***`)
|
2021-12-11 16:12:04 +00:00
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2023-09-25 09:20:46 +00:00
|
|
|
async function _listAvatars (dir: string): Promise<string[]> {
|
|
|
|
const files = await fs.promises.readdir(dir)
|
|
|
|
const r = []
|
|
|
|
for (const file of files) {
|
|
|
|
if (!file.endsWith('.jpg') && !file.endsWith('.png')) {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
r.push(file)
|
|
|
|
}
|
|
|
|
return r.sort()
|
|
|
|
}
|
|
|
|
|
2021-04-12 18:52:21 +00:00
|
|
|
export {
|
2023-04-13 10:41:54 +00:00
|
|
|
ProsodyConfig,
|
2021-04-15 10:17:08 +00:00
|
|
|
getProsodyConfig,
|
2021-04-13 15:13:41 +00:00
|
|
|
getWorkingDir,
|
|
|
|
getProsodyFilePaths,
|
2021-12-11 16:12:04 +00:00
|
|
|
writeProsodyConfig,
|
|
|
|
getProsodyConfigContentForDiagnostic
|
2021-04-12 18:52:21 +00:00
|
|
|
}
|