Builtin Prosody: use Peertube domain instead of localhost.
This commit is contained in:
@ -3,6 +3,7 @@ import * as path from 'path'
|
||||
import { pluginName, getBaseRouter } from '../helpers'
|
||||
import { ProsodyFilePaths } from './config/paths'
|
||||
import { ProsodyConfigContent } from './config/content'
|
||||
import { getProsodyDomain } from './config/domain'
|
||||
import { getAPIKey } from '../apikey'
|
||||
|
||||
async function getWorkingDir ({ peertubeHelpers, storageManager }: RegisterServerOptions): Promise<string> {
|
||||
@ -92,7 +93,7 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
|
||||
if (!/^\d+$/.test(port)) {
|
||||
throw new Error('Invalid port')
|
||||
}
|
||||
const peertubeDomain = 'localhost'
|
||||
const prosodyDomain = await getProsodyDomain(options)
|
||||
const paths = await getProsodyFilePaths(options)
|
||||
|
||||
const apikey = await getAPIKey(options)
|
||||
@ -102,9 +103,9 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
|
||||
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}'
|
||||
|
||||
const config = new ProsodyConfigContent(paths)
|
||||
const config = new ProsodyConfigContent(paths, prosodyDomain)
|
||||
config.useHttpAuthentication(authApiUrl)
|
||||
config.usePeertubeBosh(peertubeDomain, port)
|
||||
config.usePeertubeBosh(prosodyDomain, port)
|
||||
config.useMucHttpDefault(roomApiUrl)
|
||||
config.setArchive('1w') // Remove archived messages after 1 week
|
||||
config.setLog(process.env.NODE_ENV === 'test' ? 'debug' : 'info')
|
||||
|
@ -1,7 +1,10 @@
|
||||
import { getProsodyDomain } from './domain'
|
||||
|
||||
interface Affiliations { [jid: string]: 'outcast' | 'none' | 'member' | 'admin' | 'owner' }
|
||||
|
||||
async function getVideoAffiliations (options: RegisterServerOptions, video: MVideoThumbnail): Promise<Affiliations> {
|
||||
const peertubeHelpers = options.peertubeHelpers
|
||||
const prosodyDomain = await getProsodyDomain(options)
|
||||
// Get all admins and moderators
|
||||
const [results] = await peertubeHelpers.database.query(
|
||||
'SELECT "username" FROM "user"' +
|
||||
@ -19,7 +22,7 @@ async function getVideoAffiliations (options: RegisterServerOptions, video: MVid
|
||||
if (!('username' in result)) {
|
||||
throw new Error('getVideoAffiliations: no username field in result')
|
||||
}
|
||||
const jid = (result.username as string) + '@localhost'
|
||||
const jid = (result.username as string) + '@' + prosodyDomain
|
||||
r[jid] = 'owner'
|
||||
}
|
||||
|
||||
@ -29,7 +32,7 @@ async function getVideoAffiliations (options: RegisterServerOptions, video: MVid
|
||||
if (!video.remote) {
|
||||
// don't add the video owner if it is a remote video!
|
||||
const userName = await _getVideoOwnerUsername(options, video)
|
||||
const userJid = userName + '@localhost'
|
||||
const userJid = userName + '@' + prosodyDomain
|
||||
r[userJid] = 'admin'
|
||||
}
|
||||
} catch (error) {
|
||||
|
@ -103,13 +103,15 @@ class ProsodyConfigContent {
|
||||
anon: ProsodyConfigVirtualHost
|
||||
muc: ProsodyConfigComponent
|
||||
log: string
|
||||
prosodyDomain: string
|
||||
|
||||
constructor (paths: ProsodyFilePaths) {
|
||||
constructor (paths: ProsodyFilePaths, prosodyDomain: string) {
|
||||
this.paths = paths
|
||||
this.global = new ProsodyConfigGlobal()
|
||||
this.log = ''
|
||||
this.anon = new ProsodyConfigVirtualHost('anon.localhost')
|
||||
this.muc = new ProsodyConfigComponent('muc', 'room.localhost')
|
||||
this.prosodyDomain = prosodyDomain
|
||||
this.anon = new ProsodyConfigVirtualHost('anon.' + prosodyDomain)
|
||||
this.muc = new ProsodyConfigComponent('muc', 'room.' + prosodyDomain)
|
||||
|
||||
this.global.set('daemonize', false)
|
||||
this.global.set('allow_registration', false)
|
||||
@ -157,7 +159,7 @@ class ProsodyConfigContent {
|
||||
}
|
||||
|
||||
useHttpAuthentication (url: string): void {
|
||||
this.authenticated = new ProsodyConfigVirtualHost('localhost')
|
||||
this.authenticated = new ProsodyConfigVirtualHost(this.prosodyDomain)
|
||||
|
||||
this.authenticated.set('authentication', 'http')
|
||||
this.authenticated.set('modules_enabled', ['ping', 'auth_http'])
|
||||
@ -165,7 +167,7 @@ class ProsodyConfigContent {
|
||||
this.authenticated.set('http_auth_url', url)
|
||||
}
|
||||
|
||||
usePeertubeBosh (peertubeDomain: string, port: string): void {
|
||||
usePeertubeBosh (prosodyDomain: string, port: string): void {
|
||||
this.global.set('c2s_require_encryption', false)
|
||||
this.global.set('interfaces', ['127.0.0.1', '::1'])
|
||||
this.global.set('c2s_ports', [])
|
||||
@ -183,8 +185,8 @@ class ProsodyConfigContent {
|
||||
this.anon.set('allow_anonymous_s2s', false)
|
||||
this.anon.add('modules_enabled', 'http')
|
||||
this.anon.add('modules_enabled', 'bosh')
|
||||
this.anon.set('http_host', peertubeDomain)
|
||||
this.anon.set('http_external_url', 'http://' + peertubeDomain)
|
||||
this.anon.set('http_host', prosodyDomain)
|
||||
this.anon.set('http_external_url', 'http://' + prosodyDomain)
|
||||
|
||||
this.muc.set('restrict_room_creation', 'local')
|
||||
|
||||
@ -193,8 +195,8 @@ class ProsodyConfigContent {
|
||||
this.authenticated.set('allow_anonymous_s2s', false)
|
||||
this.authenticated.add('modules_enabled', 'http')
|
||||
this.authenticated.add('modules_enabled', 'bosh')
|
||||
this.authenticated.set('http_host', peertubeDomain)
|
||||
this.authenticated.set('http_external_url', 'http://' + peertubeDomain)
|
||||
this.authenticated.set('http_host', prosodyDomain)
|
||||
this.authenticated.set('http_external_url', 'http://' + prosodyDomain)
|
||||
}
|
||||
}
|
||||
|
||||
|
12
server/lib/prosody/config/domain.ts
Normal file
12
server/lib/prosody/config/domain.ts
Normal file
@ -0,0 +1,12 @@
|
||||
async function getProsodyDomain (options: RegisterServerOptions): Promise<string> {
|
||||
const url = options.peertubeHelpers.config.getWebserverUrl()
|
||||
const matches = url.match(/^https?:\/\/([^:/]*)(:\d+)?(\/|$)/)
|
||||
if (!matches) {
|
||||
throw new Error(`Cant get a domain name from url '${url}'`)
|
||||
}
|
||||
return matches[1]
|
||||
}
|
||||
|
||||
export {
|
||||
getProsodyDomain
|
||||
}
|
Reference in New Issue
Block a user