Merge branch 'release/3.2.0' into prosody_room_list
This commit is contained in:
commit
47bf53bafb
12
.github/ISSUE_TEMPLATE/bug_report.md
vendored
12
.github/ISSUE_TEMPLATE/bug_report.md
vendored
@ -3,7 +3,7 @@ name: Bug report
|
|||||||
about: Create a report to help us improve
|
about: Create a report to help us improve
|
||||||
title: ''
|
title: ''
|
||||||
labels: ''
|
labels: ''
|
||||||
assignees: ''
|
assignees: JohnXLivingston
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
@ -23,6 +23,16 @@ A clear and concise description of what you expected to happen.
|
|||||||
**Screenshots**
|
**Screenshots**
|
||||||
If applicable, add screenshots to help explain your problem.
|
If applicable, add screenshots to help explain your problem.
|
||||||
|
|
||||||
|
|
||||||
|
**Server (please complete the following information):**
|
||||||
|
- OS version [e.g. Debian 10, ...]:
|
||||||
|
- Peertube version:
|
||||||
|
- Peertube installation type [e.g. standard, docker, ...]:
|
||||||
|
- peertube-plugin-livechat version:
|
||||||
|
|
||||||
|
**Plugin diagnostic:**
|
||||||
|
If this is a server setup issue, please go to the plugin settings, click on «launch diagnostic», and copy/paste the result.
|
||||||
|
|
||||||
**Desktop (please complete the following information):**
|
**Desktop (please complete the following information):**
|
||||||
- OS: [e.g. iOS]
|
- OS: [e.g. iOS]
|
||||||
- Browser [e.g. chrome, safari]
|
- Browser [e.g. chrome, safari]
|
||||||
|
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,8 +1,17 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## v3.2.0
|
||||||
|
|
||||||
|
...
|
||||||
|
|
||||||
## v3.1.0
|
## v3.1.0
|
||||||
|
|
||||||
...
|
### Features
|
||||||
|
|
||||||
|
* Builtin Prosody: optional settings to change the url for Prosody's API calls.
|
||||||
|
* Diagnostic tool: testing API communication from Peertube to Prosody.
|
||||||
|
* Diagnostic tool: testing API communication from Prosody to Peertube.
|
||||||
|
* Diagnostic tool: correctly parse Prosody nightly build versions.
|
||||||
|
|
||||||
## v3.0.0
|
## v3.0.0
|
||||||
|
|
||||||
|
@ -111,6 +111,7 @@ function register ({ registerHook, registerSettingsScript, peertubeHelpers }: Re
|
|||||||
case 'chat-type-help-disabled':
|
case 'chat-type-help-disabled':
|
||||||
return options.formValues['chat-type'] !== ('disabled' as ChatType)
|
return options.formValues['chat-type'] !== ('disabled' as ChatType)
|
||||||
case 'prosody-port':
|
case 'prosody-port':
|
||||||
|
case 'prosody-peertube-uri':
|
||||||
case 'chat-type-help-builtin-prosody':
|
case 'chat-type-help-builtin-prosody':
|
||||||
case 'prosody-list-rooms':
|
case 'prosody-list-rooms':
|
||||||
return options.formValues['chat-type'] !== ('builtin-prosody' as ChatType)
|
return options.formValues['chat-type'] !== ('builtin-prosody' as ChatType)
|
||||||
|
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "peertube-plugin-livechat",
|
"name": "peertube-plugin-livechat",
|
||||||
"version": "3.0.0",
|
"version": "3.1.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "peertube-plugin-livechat",
|
"name": "peertube-plugin-livechat",
|
||||||
"description": "PeerTube plugin livechat",
|
"description": "PeerTube plugin livechat",
|
||||||
"version": "3.1.0",
|
"version": "3.2.0",
|
||||||
"author": "John Livingston",
|
"author": "John Livingston",
|
||||||
"bugs": "https://github.com/JohnXLivingston/peertube-plugin-livechat/issues",
|
"bugs": "https://github.com/JohnXLivingston/peertube-plugin-livechat/issues",
|
||||||
"clientScripts": [
|
"clientScripts": [
|
||||||
|
5
prosody-modules/mod_http_peertubelivechat_test/README.md
Normal file
5
prosody-modules/mod_http_peertubelivechat_test/README.md
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# mod_http_peertubelivechat_test
|
||||||
|
|
||||||
|
This module is a custom module that allows Peertube to test communication with Prosody.
|
||||||
|
|
||||||
|
This module is part of peertube-plugin-livechat, and is under the same LICENSE.
|
@ -0,0 +1,87 @@
|
|||||||
|
local json = require "util.json";
|
||||||
|
local async = require "util.async";
|
||||||
|
local http = require "net.http";
|
||||||
|
|
||||||
|
module:depends"http";
|
||||||
|
|
||||||
|
local apikey = assert(module:get_option_string("peertubelivechat_test_apikey", nil), "'peertubelivechat_test_apikey' is a required option");
|
||||||
|
local peertube_url = assert(module:get_option_string("peertubelivechat_test_peertube_api_url", nil), "'peertubelivechat_test_peertube_api_url' is a required option");
|
||||||
|
|
||||||
|
local ex = {
|
||||||
|
headers = {
|
||||||
|
accept = "application/json";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
local function check_auth(routes)
|
||||||
|
local function check_request_auth(event)
|
||||||
|
if apikey == "" then
|
||||||
|
return false, 500;
|
||||||
|
end
|
||||||
|
if event.request.headers.authorization ~= "Bearer " .. apikey then
|
||||||
|
return false, 401;
|
||||||
|
end
|
||||||
|
return true;
|
||||||
|
end
|
||||||
|
|
||||||
|
for route, handler in pairs(routes) do
|
||||||
|
routes[route] = function (event, ...)
|
||||||
|
local permit, code = check_request_auth(event);
|
||||||
|
if not permit then
|
||||||
|
return code;
|
||||||
|
end
|
||||||
|
return handler(event, ...);
|
||||||
|
end;
|
||||||
|
end
|
||||||
|
return routes;
|
||||||
|
end
|
||||||
|
|
||||||
|
local function test_peertube_prosody(event)
|
||||||
|
local request, response = event.request, event.response;
|
||||||
|
local json_response = {
|
||||||
|
ok = true;
|
||||||
|
}
|
||||||
|
event.response.headers["Content-Type"] = "application/json";
|
||||||
|
return json.encode(json_response);
|
||||||
|
end
|
||||||
|
|
||||||
|
local function test_prosody_peertube(event)
|
||||||
|
local request, response = event.request, event.response;
|
||||||
|
|
||||||
|
local ret, err;
|
||||||
|
http.request(peertube_url, ex, function (body, code)
|
||||||
|
if math.floor(code / 100) == 2 then
|
||||||
|
local parsed, parse_err = json.decode(body);
|
||||||
|
if not parsed then
|
||||||
|
module:log("debug", "Got invalid JSON from %s: %s", peertube_url, parse_err);
|
||||||
|
err = problems.format;
|
||||||
|
else
|
||||||
|
ret = parsed;
|
||||||
|
end
|
||||||
|
else
|
||||||
|
module:log("debug", "Rejected by API: ", body);
|
||||||
|
err = "Rejected by API";
|
||||||
|
end
|
||||||
|
|
||||||
|
local json_response;
|
||||||
|
if not ret then
|
||||||
|
json_response = {
|
||||||
|
ok = false;
|
||||||
|
error = err;
|
||||||
|
};
|
||||||
|
else
|
||||||
|
json_response = ret;
|
||||||
|
end
|
||||||
|
response:send(json.encode(json_response));
|
||||||
|
end);
|
||||||
|
|
||||||
|
event.response.headers["Content-Type"] = "application/json";
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
module:provides("http", {
|
||||||
|
route = check_auth {
|
||||||
|
["GET /test-peertube-prosody"] = test_peertube_prosody;
|
||||||
|
["GET /test-prosody-peertube"] = test_prosody_peertube;
|
||||||
|
};
|
||||||
|
});
|
@ -1,8 +1,11 @@
|
|||||||
import { getProsodyConfig, getWorkingDir } from '../prosody/config'
|
import { getProsodyConfig, getWorkingDir } from '../prosody/config'
|
||||||
import { getProsodyAbout, testProsodyCorrectlyRunning } from '../prosody/ctl'
|
import { getProsodyAbout, testProsodyCorrectlyRunning } from '../prosody/ctl'
|
||||||
import { newResult, TestResult } from './utils'
|
import { newResult, TestResult } from './utils'
|
||||||
|
import { getAPIKey } from '../apikey'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'fs'
|
||||||
|
|
||||||
|
const got = require('got')
|
||||||
|
|
||||||
export async function diagProsody (test: string, options: RegisterServerOptions): Promise<TestResult> {
|
export async function diagProsody (test: string, options: RegisterServerOptions): Promise<TestResult> {
|
||||||
const result = newResult(test)
|
const result = newResult(test)
|
||||||
result.label = 'Builtin Prosody and ConverseJS'
|
result.label = 'Builtin Prosody and ConverseJS'
|
||||||
@ -17,11 +20,15 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
|
|||||||
|
|
||||||
// FIXME: these tests are very similar to tests in testProsodyCorrectlyRunning. Remove from here?
|
// FIXME: these tests are very similar to tests in testProsodyCorrectlyRunning. Remove from here?
|
||||||
// Testing the prosody config file.
|
// Testing the prosody config file.
|
||||||
|
let prosodyPort: string
|
||||||
try {
|
try {
|
||||||
const wantedConfig = await getProsodyConfig(options)
|
const wantedConfig = await getProsodyConfig(options)
|
||||||
const filePath = wantedConfig.paths.config
|
const filePath = wantedConfig.paths.config
|
||||||
|
|
||||||
result.messages.push(`Prosody will run on port '${wantedConfig.port}'`)
|
result.messages.push(`Prosody will run on port '${wantedConfig.port}'`)
|
||||||
|
prosodyPort = wantedConfig.port
|
||||||
|
|
||||||
|
result.messages.push(`Prosody will use ${wantedConfig.baseApiUrl} as base uri from api calls`)
|
||||||
|
|
||||||
result.messages.push(`Prosody modules path will be '${wantedConfig.paths.modules}'`)
|
result.messages.push(`Prosody modules path will be '${wantedConfig.paths.modules}'`)
|
||||||
|
|
||||||
@ -67,7 +74,7 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
const versionMatches = about.match(/^Prosody\s*(\d+)\.(\d+)\.(\d+)\s*$/mi)
|
const versionMatches = about.match(/^Prosody\s*(\d+)\.(\d+)(?:\.(\d+)| (nightly build \d+.*))\s*$/mi)
|
||||||
if (!versionMatches) {
|
if (!versionMatches) {
|
||||||
result.messages.push({
|
result.messages.push({
|
||||||
level: 'error',
|
level: 'error',
|
||||||
@ -77,7 +84,7 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
|
|||||||
} else {
|
} else {
|
||||||
const major = versionMatches[1]
|
const major = versionMatches[1]
|
||||||
const minor = versionMatches[2]
|
const minor = versionMatches[2]
|
||||||
const patch = versionMatches[3]
|
const patch = versionMatches[3] ?? versionMatches[4]
|
||||||
result.messages.push(`Prosody version is ${major}.${minor}.${patch}`)
|
result.messages.push(`Prosody version is ${major}.${minor}.${patch}`)
|
||||||
if (major !== '0' && minor !== '11') {
|
if (major !== '0' && minor !== '11') {
|
||||||
result.messages.push({
|
result.messages.push({
|
||||||
@ -87,6 +94,48 @@ export async function diagProsody (test: string, options: RegisterServerOptions)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const apiUrl = `http://localhost:${prosodyPort}/peertubelivechat_test/test-peertube-prosody`
|
||||||
|
const testResult = await got(apiUrl, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
authorization: 'Bearer ' + await getAPIKey(options)
|
||||||
|
},
|
||||||
|
responseType: 'json',
|
||||||
|
resolveBodyOnly: true
|
||||||
|
})
|
||||||
|
if (testResult.ok === true) {
|
||||||
|
result.messages.push('API Peertube -> Prosody is OK')
|
||||||
|
} else {
|
||||||
|
result.messages.push('API Peertube -> Prosody is KO. Response was: ' + JSON.stringify(testResult))
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
result.messages.push('Error when calling Prosody test api (test-peertube-prosody): ' + (error as string))
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const apiUrl = `http://localhost:${prosodyPort}/peertubelivechat_test/test-prosody-peertube`
|
||||||
|
const testResult = await got(apiUrl, {
|
||||||
|
method: 'GET',
|
||||||
|
headers: {
|
||||||
|
authorization: 'Bearer ' + await getAPIKey(options)
|
||||||
|
},
|
||||||
|
responseType: 'json',
|
||||||
|
resolveBodyOnly: true
|
||||||
|
})
|
||||||
|
if (testResult.ok === true) {
|
||||||
|
result.messages.push('API Prosody -> Peertube is OK')
|
||||||
|
} else {
|
||||||
|
result.messages.push('API Prosody -> Peertube is KO. Response was: ' + JSON.stringify(testResult))
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
result.messages.push('Error when calling Prosody test api (test-prosody-peertube): ' + (error as string))
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
result.ok = true
|
result.ok = true
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ interface ProsodyConfig {
|
|||||||
content: string
|
content: string
|
||||||
paths: ProsodyFilePaths
|
paths: ProsodyFilePaths
|
||||||
port: string
|
port: string
|
||||||
|
baseApiUrl: string
|
||||||
}
|
}
|
||||||
async function getProsodyConfig (options: RegisterServerOptions): Promise<ProsodyConfig> {
|
async function getProsodyConfig (options: RegisterServerOptions): Promise<ProsodyConfig> {
|
||||||
const logger = options.peertubeHelpers.logger
|
const logger = options.peertubeHelpers.logger
|
||||||
@ -80,11 +81,18 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
|
|||||||
const paths = await getProsodyFilePaths(options)
|
const paths = await getProsodyFilePaths(options)
|
||||||
|
|
||||||
const apikey = await getAPIKey(options)
|
const apikey = await getAPIKey(options)
|
||||||
const baseApiUrl = options.peertubeHelpers.config.getWebserverUrl() +
|
let baseApiUrl = await options.settingsManager.getSetting('prosody-peertube-uri') as string
|
||||||
getBaseRouterRoute(options) +
|
if (baseApiUrl && !/^https?:\/\/[a-z0-9.-_]+(?::\d+)?$/.test(baseApiUrl)) {
|
||||||
'api/'
|
throw new Error('Invalid prosody-peertube-uri')
|
||||||
|
}
|
||||||
|
if (!baseApiUrl) {
|
||||||
|
baseApiUrl = options.peertubeHelpers.config.getWebserverUrl()
|
||||||
|
}
|
||||||
|
baseApiUrl += getBaseRouterRoute(options) + 'api/'
|
||||||
|
|
||||||
const authApiUrl = baseApiUrl + 'user' // FIXME: should be protected by apikey, but mod_auth_http cant handle params
|
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 roomApiUrl = baseApiUrl + 'room?apikey=' + apikey + '&jid={room.jid|jid_node}'
|
||||||
|
const testApiUrl = baseApiUrl + 'test?apikey=' + apikey
|
||||||
|
|
||||||
const config = new ProsodyConfigContent(paths, prosodyDomain)
|
const config = new ProsodyConfigContent(paths, prosodyDomain)
|
||||||
config.useHttpAuthentication(authApiUrl)
|
config.useHttpAuthentication(authApiUrl)
|
||||||
@ -98,6 +106,8 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
|
|||||||
|
|
||||||
config.useListRoomsApi(apikey)
|
config.useListRoomsApi(apikey)
|
||||||
|
|
||||||
|
config.useTestModule(apikey, testApiUrl)
|
||||||
|
|
||||||
let logLevel: ProsodyLogLevel | undefined
|
let logLevel: ProsodyLogLevel | undefined
|
||||||
if (logger.level && (typeof logger.level === 'string')) {
|
if (logger.level && (typeof logger.level === 'string')) {
|
||||||
if (logger.level === 'error' || logger.level === 'info' || logger.level === 'debug') {
|
if (logger.level === 'error' || logger.level === 'info' || logger.level === 'debug') {
|
||||||
@ -117,7 +127,8 @@ async function getProsodyConfig (options: RegisterServerOptions): Promise<Prosod
|
|||||||
return {
|
return {
|
||||||
content,
|
content,
|
||||||
paths,
|
paths,
|
||||||
port
|
port,
|
||||||
|
baseApiUrl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -241,6 +241,12 @@ class ProsodyConfigContent {
|
|||||||
this.muc.set('peertubelivechat_list_rooms_apikey', apikey)
|
this.muc.set('peertubelivechat_list_rooms_apikey', apikey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useTestModule (prosodyApikey: string, apiurl: string): void {
|
||||||
|
this.global.add('modules_enabled', 'http_peertubelivechat_test')
|
||||||
|
this.global.set('peertubelivechat_test_apikey', prosodyApikey)
|
||||||
|
this.global.set('peertubelivechat_test_peertube_api_url', apiurl)
|
||||||
|
}
|
||||||
|
|
||||||
setLog (level: ProsodyLogLevel, syslog?: ProsodyLogLevel[]): void {
|
setLog (level: ProsodyLogLevel, syslog?: ProsodyLogLevel[]): void {
|
||||||
let log = ''
|
let log = ''
|
||||||
log += 'log = {\n'
|
log += 'log = {\n'
|
||||||
|
@ -34,6 +34,14 @@ async function initApiRouter (options: RegisterServerOptions): Promise<Router> {
|
|||||||
const router = getRouter()
|
const router = getRouter()
|
||||||
const logger = peertubeHelpers.logger
|
const logger = peertubeHelpers.logger
|
||||||
|
|
||||||
|
router.get('/test', asyncMiddleware([
|
||||||
|
getCheckAPIKeyMiddleware(options),
|
||||||
|
async (req: Request, res: Response, _next: NextFunction) => {
|
||||||
|
logger.info('Test api call')
|
||||||
|
res.json({ ok: true })
|
||||||
|
}
|
||||||
|
]))
|
||||||
|
|
||||||
router.get('/room', asyncMiddleware([
|
router.get('/room', asyncMiddleware([
|
||||||
getCheckAPIKeyMiddleware(options),
|
getCheckAPIKeyMiddleware(options),
|
||||||
async (req: Request, res: Response, _next: NextFunction) => {
|
async (req: Request, res: Response, _next: NextFunction) => {
|
||||||
|
@ -110,6 +110,18 @@ Change it if this port is already in use on your server.<br>
|
|||||||
You can close this port on your firewall, it will not be accessed from the outer world.`
|
You can close this port on your firewall, it will not be accessed from the outer world.`
|
||||||
})
|
})
|
||||||
|
|
||||||
|
registerSetting({
|
||||||
|
name: 'prosody-peertube-uri',
|
||||||
|
label: 'Peertube url for API calls',
|
||||||
|
type: 'input',
|
||||||
|
default: '',
|
||||||
|
private: true,
|
||||||
|
descriptionHTML:
|
||||||
|
`Please let this settings empty if you don't know what you are doing.<br>
|
||||||
|
In some rare case, Prosody can't call Peertube's API from its public URI.
|
||||||
|
You can use this field to customise Peertube's URI for Prosody modules (for example with «http://localhost:9000»).`
|
||||||
|
})
|
||||||
|
|
||||||
registerSetting({
|
registerSetting({
|
||||||
name: 'chat-server',
|
name: 'chat-server',
|
||||||
label: 'XMPP service server',
|
label: 'XMPP service server',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user