Fix bot authentication.
This commit is contained in:
parent
de9de8e358
commit
e0c31f09aa
@ -1,9 +1,5 @@
|
|||||||
# mod_bot_peertubelivechat
|
# mod_bot_peertubelivechat
|
||||||
|
|
||||||
This module is a custom module for the Peertube livechat plugin, that handle the bot virtualhost.
|
This module is a custom module for the Peertube livechat plugin, that handle bots authentication.
|
||||||
It provide several functions:
|
|
||||||
|
|
||||||
* bot authentication
|
|
||||||
* bot vcards (TODO)
|
|
||||||
|
|
||||||
This module is part of peertube-plugin-livechat, and is under the same LICENSE.
|
This module is part of peertube-plugin-livechat, and is under the same LICENSE.
|
@ -10,11 +10,6 @@
|
|||||||
local new_sasl = require "util.sasl".new;
|
local new_sasl = require "util.sasl".new;
|
||||||
local path = require "util.paths";
|
local path = require "util.paths";
|
||||||
local json = require "util.json";
|
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 host = module.host;
|
||||||
local provider = {};
|
local provider = {};
|
||||||
@ -22,9 +17,11 @@ local provider = {};
|
|||||||
local bot_conf_folder = module:get_option_string('livechat_bot_conf_folder', '');
|
local bot_conf_folder = module:get_option_string('livechat_bot_conf_folder', '');
|
||||||
|
|
||||||
function read_global_conf(filename)
|
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
|
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;
|
return nil;
|
||||||
end
|
end
|
||||||
local content = file:read("*all");
|
local content = file:read("*all");
|
||||||
@ -32,16 +29,19 @@ function read_global_conf(filename)
|
|||||||
|
|
||||||
local o = json.decode(content);
|
local o = json.decode(content);
|
||||||
if (not o) then
|
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;
|
return nil;
|
||||||
end
|
end
|
||||||
if (not o["connection"]) then
|
if (not o["connection"]) then
|
||||||
|
module:log("debug", "No connection info in bot global conf file", filename);
|
||||||
return nil;
|
return nil;
|
||||||
end
|
end
|
||||||
if (not o["connection"]["username"]) then
|
if (not o["connection"]["username"]) then
|
||||||
|
module:log("debug", "No connection.username info in bot global conf file", filename);
|
||||||
return nil;
|
return nil;
|
||||||
end
|
end
|
||||||
if (not o["connection"]["password"]) then
|
if (not o["connection"]["password"]) then
|
||||||
|
module:log("debug", "No connection.password info in bot global conf file", filename);
|
||||||
return nil;
|
return nil;
|
||||||
end
|
end
|
||||||
result = {
|
result = {
|
||||||
@ -53,7 +53,7 @@ end
|
|||||||
|
|
||||||
function provider.test_password(username, password)
|
function provider.test_password(username, password)
|
||||||
-- FIXME: adapt the code for multiple bots
|
-- 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
|
if (credentials and credentials["username"] == username and credentials["password"] == password) then
|
||||||
return true;
|
return true;
|
||||||
end
|
end
|
||||||
@ -72,7 +72,7 @@ end
|
|||||||
|
|
||||||
function provider.user_exists(username)
|
function provider.user_exists(username)
|
||||||
-- FIXME: adapt the code for multiple bots
|
-- 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
|
if (credentials and credentials["username"] == username) then
|
||||||
return true;
|
return true;
|
||||||
end
|
end
|
@ -436,14 +436,13 @@ class ProsodyConfigContent {
|
|||||||
*/
|
*/
|
||||||
useBotsVirtualHost (): void {
|
useBotsVirtualHost (): void {
|
||||||
this.bot = new ProsodyConfigVirtualHost('bot.' + this.prosodyDomain)
|
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()
|
const configurationPaths = BotConfiguration.singleton().configurationPaths()
|
||||||
if (configurationPaths.moderation?.globalDir) {
|
if (configurationPaths.moderation?.globalDir) {
|
||||||
this.bot.set('livechat_bot_conf_folder', configurationPaths.moderation.globalDir)
|
this.bot.set('livechat_bot_conf_folder', configurationPaths.moderation.globalDir)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: bot vcards
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setLog (level: ProsodyLogLevel, syslog?: ProsodyLogLevel[]): void {
|
setLog (level: ProsodyLogLevel, syslog?: ProsodyLogLevel[]): void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user