Fix bot authentication.

This commit is contained in:
John Livingston 2023-09-19 17:55:37 +02:00
parent de9de8e358
commit e0c31f09aa
No known key found for this signature in database
GPG Key ID: B17B5640CE66CDBC
3 changed files with 13 additions and 18 deletions

View File

@ -1,9 +1,5 @@
# mod_bot_peertubelivechat
This module is a custom module for the Peertube livechat plugin, that handle the bot virtualhost.
It provide several functions:
* bot authentication
* bot vcards (TODO)
This module is a custom module for the Peertube livechat plugin, that handle bots authentication.
This module is part of peertube-plugin-livechat, and is under the same LICENSE.

View File

@ -10,11 +10,6 @@
local new_sasl = require "util.sasl".new;
local path = require "util.paths";
local json = require "util.json";
-- local have_async, async = pcall(require, "util.async");
-- if not have_async then
-- error("Your version of Prosody does not support async and is incompatible");
-- end
local host = module.host;
local provider = {};
@ -22,9 +17,11 @@ local provider = {};
local bot_conf_folder = module:get_option_string('livechat_bot_conf_folder', '');
function read_global_conf(filename)
local file = io.open(path.join(bot_conf_folder, filename), "r");
full_path = path.join(bot_conf_folder, filename);
module:log("debug", "Reading bot global conf file", full_path);
local file = io.open(full_path, "r");
if file == nil then
module:log("debug", "Cant read global conf file", filename);
module:log("debug", "Cant read bot global conf file", filename);
return nil;
end
local content = file:read("*all");
@ -32,16 +29,19 @@ function read_global_conf(filename)
local o = json.decode(content);
if (not o) then
module:log("error", "Cant json-decode file", filename);
module:log("error", "Cant json-decode bot global conf file", filename);
return nil;
end
if (not o["connection"]) then
module:log("debug", "No connection info in bot global conf file", filename);
return nil;
end
if (not o["connection"]["username"]) then
module:log("debug", "No connection.username info in bot global conf file", filename);
return nil;
end
if (not o["connection"]["password"]) then
module:log("debug", "No connection.password info in bot global conf file", filename);
return nil;
end
result = {
@ -53,7 +53,7 @@ end
function provider.test_password(username, password)
-- FIXME: adapt the code for multiple bots
credentials = read_global_conf("moderator.json")
credentials = read_global_conf("moderation.json")
if (credentials and credentials["username"] == username and credentials["password"] == password) then
return true;
end
@ -72,7 +72,7 @@ end
function provider.user_exists(username)
-- FIXME: adapt the code for multiple bots
credentials = read_global_conf("moderator.json")
credentials = read_global_conf("moderation.json")
if (credentials and credentials["username"] == username) then
return true;
end

View File

@ -436,14 +436,13 @@ class ProsodyConfigContent {
*/
useBotsVirtualHost (): void {
this.bot = new ProsodyConfigVirtualHost('bot.' + this.prosodyDomain)
this.bot.set('modules_enabled', ['ping', 'bot_peertubelivechat'])
this.bot.set('modules_enabled', ['ping'])
this.bot.set('authentication', 'peertubelivechat_bot')
const configurationPaths = BotConfiguration.singleton().configurationPaths()
if (configurationPaths.moderation?.globalDir) {
this.bot.set('livechat_bot_conf_folder', configurationPaths.moderation.globalDir)
}
// TODO: bot vcards
}
setLog (level: ProsodyLogLevel, syslog?: ProsodyLogLevel[]): void {