From e0c31f09aae74c1d005cddc1d3b0911507a265ff Mon Sep 17 00:00:00 2001 From: John Livingston Date: Tue, 19 Sep 2023 17:55:37 +0200 Subject: [PATCH] Fix bot authentication. --- .../README.md | 6 +----- .../mod_auth_peertubelivechat_bot.lua} | 20 +++++++++---------- server/lib/prosody/config/content.ts | 5 ++--- 3 files changed, 13 insertions(+), 18 deletions(-) rename prosody-modules/{mod_bot_peertubelivechat => mod_auth_peertubelivechat_bot}/README.md (62%) rename prosody-modules/{mod_bot_peertubelivechat/mod_bot_peertubelivechat.lua => mod_auth_peertubelivechat_bot/mod_auth_peertubelivechat_bot.lua} (74%) diff --git a/prosody-modules/mod_bot_peertubelivechat/README.md b/prosody-modules/mod_auth_peertubelivechat_bot/README.md similarity index 62% rename from prosody-modules/mod_bot_peertubelivechat/README.md rename to prosody-modules/mod_auth_peertubelivechat_bot/README.md index 493e848b..767d8a51 100644 --- a/prosody-modules/mod_bot_peertubelivechat/README.md +++ b/prosody-modules/mod_auth_peertubelivechat_bot/README.md @@ -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. diff --git a/prosody-modules/mod_bot_peertubelivechat/mod_bot_peertubelivechat.lua b/prosody-modules/mod_auth_peertubelivechat_bot/mod_auth_peertubelivechat_bot.lua similarity index 74% rename from prosody-modules/mod_bot_peertubelivechat/mod_bot_peertubelivechat.lua rename to prosody-modules/mod_auth_peertubelivechat_bot/mod_auth_peertubelivechat_bot.lua index 1cd8a209..a2d39036 100644 --- a/prosody-modules/mod_bot_peertubelivechat/mod_bot_peertubelivechat.lua +++ b/prosody-modules/mod_auth_peertubelivechat_bot/mod_auth_peertubelivechat_bot.lua @@ -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 diff --git a/server/lib/prosody/config/content.ts b/server/lib/prosody/config/content.ts index ea4f376e..e63af328 100644 --- a/server/lib/prosody/config/content.ts +++ b/server/lib/prosody/config/content.ts @@ -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 {