Builtin Prosody: use Peertube domain instead of localhost.
This commit is contained in:
parent
2e7c5b295a
commit
f590cf2c7b
@ -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
|
||||
}
|
@ -5,6 +5,7 @@ import { getCheckAPIKeyMiddleware } from '../middlewares/apikey'
|
||||
import { prosodyCheckUserPassword, prosodyRegisterUser, prosodyUserRegistered } from '../prosody/auth'
|
||||
import { getAuthUser, getUserNickname } from '../helpers'
|
||||
import { Affiliations, getVideoAffiliations } from '../prosody/config/affiliations'
|
||||
import { getProsodyDomain } from '../prosody/config/domain'
|
||||
|
||||
// See here for description: https://modules.prosody.im/mod_muc_http_defaults.html
|
||||
interface RoomDefaults {
|
||||
@ -100,10 +101,11 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
||||
res.sendStatus(403)
|
||||
return
|
||||
}
|
||||
const prosodyDomain = await getProsodyDomain(options)
|
||||
const password: string = await prosodyRegisterUser(user.username)
|
||||
const nickname: string | undefined = await getUserNickname(options, user)
|
||||
res.status(200).json({
|
||||
jid: user.username + '@localhost',
|
||||
jid: user.username + '@' + prosodyDomain,
|
||||
password: password,
|
||||
nickname: nickname
|
||||
})
|
||||
@ -130,10 +132,11 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
||||
res.status(200).send('false')
|
||||
return
|
||||
}
|
||||
const prosodyDomain = await getProsodyDomain(options)
|
||||
const user = req.query.user
|
||||
const server = req.query.server
|
||||
const pass = req.query.pass
|
||||
if (server !== 'localhost') {
|
||||
if (server !== prosodyDomain) {
|
||||
logger.warn(`Cannot call check_password on user on server ${server as string}.`)
|
||||
res.status(200).send('false')
|
||||
return
|
||||
@ -160,9 +163,10 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
||||
res.status(200).send('false')
|
||||
return
|
||||
}
|
||||
const prosodyDomain = await getProsodyDomain(options)
|
||||
const user = req.query.user
|
||||
const server = req.query.server
|
||||
if (server !== 'localhost') {
|
||||
if (server !== prosodyDomain) {
|
||||
logger.warn(`Cannot call user_exists on user on server ${server as string}.`)
|
||||
res.status(200).send('false')
|
||||
return
|
||||
|
@ -2,6 +2,7 @@ import type { Router, RequestHandler, Request, Response, NextFunction } from 'ex
|
||||
import type { ProxyOptions } from 'express-http-proxy'
|
||||
import { getBaseRouter } from '../helpers'
|
||||
import { asyncMiddleware } from '../middlewares/async'
|
||||
import { getProsodyDomain } from '../prosody/config/domain'
|
||||
import * as path from 'path'
|
||||
const bodyParser = require('body-parser')
|
||||
|
||||
@ -35,8 +36,9 @@ async function initWebchatRouter (options: RegisterServerOptions): Promise<Route
|
||||
let authenticationUrl: string = ''
|
||||
let advancedControls: boolean = false
|
||||
if (settings['chat-use-prosody']) {
|
||||
server = 'anon.localhost'
|
||||
room = '{{VIDEO_UUID}}@room.localhost'
|
||||
const prosodyDomain = await getProsodyDomain(options)
|
||||
server = 'anon.' + prosodyDomain
|
||||
room = '{{VIDEO_UUID}}@room.' + prosodyDomain
|
||||
boshUri = getBaseRouter() + 'webchat/http-bind'
|
||||
wsUri = ''
|
||||
authenticationUrl = options.peertubeHelpers.config.getWebserverUrl() +
|
||||
|
Loading…
x
Reference in New Issue
Block a user