Fix Prosody room topic:
Due to a bug in mod_muc_http_defaults (https://hg.prosody.im/prosody-modules/rev/6d99ddd99694), room topics were badly configured. The plugin will fix them at startup, and stops trying to set the subject.
This commit is contained in:
parent
4d6ead2621
commit
d359d3ad99
@ -10,6 +10,7 @@
|
||||
|
||||
* Diagnostic tool: add the result of `prosodyctl check` in the debug section.
|
||||
* New debug mode
|
||||
* Fix room topic: due to a [bug in mod_muc_http_defaults](https://hg.prosody.im/prosody-modules/rev/6d99ddd99694), room topics were badly configured. The plugin will fix them at startup, and stops trying to set the subject.
|
||||
|
||||
## 6.2.3
|
||||
|
||||
|
@ -5,6 +5,7 @@ import {
|
||||
ensureProsodyCertificates, startProsodyCertificatesRenewCheck, stopProsodyCertificatesRenewCheck
|
||||
} from './certificates'
|
||||
import { disableProxyRoute, enableProxyRoute } from '../routers/webchat'
|
||||
import { fixRoomSubject } from './fix-room-subject'
|
||||
import * as fs from 'fs'
|
||||
import * as child_process from 'child_process'
|
||||
|
||||
@ -71,6 +72,12 @@ async function prepareProsody (options: RegisterServerOptions): Promise<void> {
|
||||
filePaths.appImageExtractPath
|
||||
)
|
||||
|
||||
try {
|
||||
await fixRoomSubject(options, filePaths)
|
||||
} catch (err) {
|
||||
logger.error(err)
|
||||
}
|
||||
|
||||
const appImageToExtract = filePaths.appImageToExtract
|
||||
if (!appImageToExtract) {
|
||||
return
|
||||
|
56
server/lib/prosody/fix-room-subject.ts
Normal file
56
server/lib/prosody/fix-room-subject.ts
Normal file
@ -0,0 +1,56 @@
|
||||
import type { RegisterServerOptions } from '@peertube/peertube-types'
|
||||
import { ProsodyFilePaths } from './config/paths'
|
||||
import * as path from 'path'
|
||||
import * as fs from 'fs'
|
||||
|
||||
/**
|
||||
* Until plugin verstion 6.2.3, there where a bug in mod_muc_http_defaults
|
||||
* that messed up room metadata. This bug is blocking for external XMPP account
|
||||
* connections.
|
||||
* This functions corrects room metadata if needed.
|
||||
* @param options
|
||||
* @param filePaths
|
||||
*/
|
||||
export async function fixRoomSubject (options: RegisterServerOptions, filePaths: ProsodyFilePaths): Promise<void> {
|
||||
const logger = options.peertubeHelpers.logger
|
||||
// When this scripts run the first time, it create a file, so that we can know if we need to run it again:
|
||||
const doneFilePath = path.resolve(filePaths.dir, 'fix-room-done')
|
||||
if (fs.existsSync(doneFilePath)) {
|
||||
logger.debug('fixRoomSubject already runned.')
|
||||
return
|
||||
}
|
||||
|
||||
logger.info('Fixing Prosody room subjects...')
|
||||
|
||||
// Room data are in a folder named something like "room%2evideos%2edomain%2etld".
|
||||
// There should only be one. But if you renamed your instance, it could be more than one.
|
||||
// Just in case, we will loop on each folder with name beginning with "room%2e".
|
||||
const folders = fs.readdirSync(filePaths.data, { withFileTypes: true }).filter(file => {
|
||||
return file.isDirectory() && file.name.startsWith('room%2e')
|
||||
})
|
||||
folders.forEach(folder => {
|
||||
// the folder must contain a «config» directory
|
||||
const configDir = path.resolve(filePaths.data, folder.name, 'config')
|
||||
if (!fs.existsSync(configDir)) { return }
|
||||
const roomDataFiles = fs.readdirSync(configDir, { withFileTypes: true }).filter(file => {
|
||||
return file.isFile() && file.name.endsWith('.dat')
|
||||
})
|
||||
roomDataFiles.forEach(file => {
|
||||
logger.debug('Checking room ' + file.name + ' subject')
|
||||
const filepath = path.resolve(configDir, file.name)
|
||||
let content = fs.readFileSync(filepath).toString()
|
||||
// To detect wrongly configured files, we just check if there is a "subject_from" and no "subject" key.
|
||||
// Indeed, the bug was that mod_muc_http_defaults set subject_from (which should be a jid) to the subject, and
|
||||
// did not set any subject.
|
||||
// See https://hg.prosody.im/prosody-modules/rev/6d99ddd99694
|
||||
if (content.includes('["subject_from"]') && !content.includes('["subject"]')) {
|
||||
logger.info('We must fix room ' + file.name + ' by removing subject_from')
|
||||
content = content.replace(/^\s*\["subject_from"\]\s*=.*;\s*$/gm, '')
|
||||
content = content.replace(/^\s*\["subject_time"\]\s*=.*;\s*$/gm, '')
|
||||
fs.writeFileSync(filepath, content)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
fs.writeFileSync(doneFilePath, '')
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user