Rewriting the prosody config generator code.
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
import * as fs from 'fs'
|
||||
import * as path from 'path'
|
||||
import { pluginName, getBaseRouter } from '../helpers'
|
||||
|
||||
type LogMode = 'debug' | 'info'
|
||||
import { ProsodyFilePaths } from './config/paths'
|
||||
import { ProsodyConfigContent } from './config/content'
|
||||
|
||||
async function getWorkingDir ({ peertubeHelpers, storageManager }: RegisterServerOptions): Promise<string> {
|
||||
const logger = peertubeHelpers.logger
|
||||
@ -62,15 +62,6 @@ async function ensureWorkingDir (options: RegisterServerOptions): Promise<string
|
||||
return dir
|
||||
}
|
||||
|
||||
interface ProsodyFilePaths {
|
||||
dir: string
|
||||
pid: string
|
||||
error: string
|
||||
log: string
|
||||
config: string
|
||||
data: string
|
||||
modules: string
|
||||
}
|
||||
async function getProsodyFilePaths (options: RegisterServerOptions): Promise<ProsodyFilePaths> {
|
||||
const logger = options.peertubeHelpers.logger
|
||||
logger.debug('Calling getProsodyFilePaths')
|
||||
@ -87,14 +78,6 @@ async function getProsodyFilePaths (options: RegisterServerOptions): Promise<Pro
|
||||
}
|
||||
}
|
||||
|
||||
interface ProsodyModuleConfig {
|
||||
module: string
|
||||
options: Array<{
|
||||
name: string
|
||||
value: string
|
||||
}>
|
||||
}
|
||||
|
||||
interface ProsodyConfig {
|
||||
content: string
|
||||
paths: ProsodyFilePaths
|
||||
@ -110,111 +93,17 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
|
||||
}
|
||||
const peertubeDomain = 'localhost'
|
||||
const paths = await getProsodyFilePaths(options)
|
||||
const logMode: LogMode = process.env.NODE_ENV === 'test' ? 'debug' : 'info'
|
||||
|
||||
const mucModules: ProsodyModuleConfig[] = []
|
||||
const roomApiUrl = options.peertubeHelpers.config.getWebserverUrl() +
|
||||
getBaseRouter() +
|
||||
'api/room?{room.jid|jid_node}'
|
||||
|
||||
mucModules.push({
|
||||
module: 'muc_http_defaults',
|
||||
options: [
|
||||
{
|
||||
name: 'muc_create_api_url',
|
||||
value: options.peertubeHelpers.config.getWebserverUrl() + getBaseRouter() + 'api/room'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
const mucModulesEnabled: string = mucModules.map(m => ' "' + m.module + '";').join('\n')
|
||||
const mucModulesOptions: string = mucModules.map(m => {
|
||||
return m.options.map(o => {
|
||||
return ' ' + o.name + ' = "' + o.value + '"'
|
||||
}).join('\n')
|
||||
}).join('\n')
|
||||
|
||||
const content = `
|
||||
|
||||
daemonize = false
|
||||
pidfile = "${paths.pid}"
|
||||
plugin_paths = { "${paths.modules}" }
|
||||
data_path = "${paths.data}"
|
||||
interfaces = { "127.0.0.1" }
|
||||
c2s_ports = { }
|
||||
c2s_interfaces = { "127.0.0.1" }
|
||||
s2s_ports = { }
|
||||
s2s_interfaces = { "127.0.0.1" }
|
||||
http_ports = { "${port}" }
|
||||
http_interfaces = { "127.0.0.1" }
|
||||
https_ports = { }
|
||||
https_interfaces = { "127.0.0.1" }
|
||||
|
||||
admins = { }
|
||||
|
||||
modules_enabled = {
|
||||
"roster"; -- Allow users to have a roster. Recommended ;)
|
||||
"saslauth"; -- Authentication for clients and servers. Recommended if you want to log in.
|
||||
"version"; -- Replies to server version requests
|
||||
"uptime"; -- Report how long server has been running
|
||||
"ping"; -- Replies to XMPP pings with pongs
|
||||
|
||||
"bosh"; -- Enable BOSH clients, aka "Jabber over HTTP"
|
||||
|
||||
"posix"; -- POSIX functionality, sends server to background, enables syslog, etc.
|
||||
}
|
||||
modules_disabled = {
|
||||
-- "offline"; -- Store offline messages
|
||||
-- "c2s"; -- Handle client connections
|
||||
"s2s"; -- Handle server-to-server connections
|
||||
}
|
||||
|
||||
allow_registration = false
|
||||
|
||||
c2s_require_encryption = false
|
||||
|
||||
archive_expires_after = "1w" -- Remove archived messages after 1 week
|
||||
|
||||
log = {
|
||||
-- Log files (change 'info' to 'debug' for debug logs):
|
||||
${logMode} = "${paths.log}";
|
||||
error = "${paths.error}";
|
||||
-- Syslog:
|
||||
-- { levels = { "error" }; to = "syslog"; };
|
||||
}
|
||||
|
||||
cross_domain_bosh = false
|
||||
consider_bosh_secure = true
|
||||
cross_domain_websocket = false
|
||||
consider_websocket_secure = true
|
||||
|
||||
VirtualHost "localhost"
|
||||
trusted_proxies = { "127.0.0.1", "::1" }
|
||||
|
||||
authentication = "anonymous"
|
||||
allow_anonymous_s2s = false
|
||||
modules_enabled = {
|
||||
"http";
|
||||
"bosh";
|
||||
"ping";
|
||||
}
|
||||
http_host = "${peertubeDomain}"
|
||||
http_external_url = "http://${peertubeDomain}"
|
||||
|
||||
Component "room.localhost" "muc"
|
||||
restrict_room_creation = "local"
|
||||
modules_enabled = {
|
||||
${mucModulesEnabled}
|
||||
}
|
||||
muc_room_locking = false
|
||||
muc_tombstones = false
|
||||
muc_room_default_language = "en"
|
||||
muc_room_default_public = true
|
||||
muc_room_default_persistent = false
|
||||
muc_room_default_members_only = false
|
||||
muc_room_default_moderated = false
|
||||
muc_room_default_public_jids = false
|
||||
muc_room_default_change_subject = false
|
||||
muc_room_default_history_length = 20
|
||||
${mucModulesOptions}
|
||||
`
|
||||
const config = new ProsodyConfigContent(paths)
|
||||
config.usePeertubeBosh(peertubeDomain, port)
|
||||
config.useMucHttpDefault(roomApiUrl)
|
||||
config.setArchive('1w') // Remove archived messages after 1 week
|
||||
config.setLog(process.env.NODE_ENV === 'test' ? 'debug' : 'info')
|
||||
const content = config.write()
|
||||
|
||||
return {
|
||||
content,
|
||||
|
Reference in New Issue
Block a user