From ab6b7d7a69a47225fe3f802f9970ab80e7f38dee Mon Sep 17 00:00:00 2001 From: Madpeter Date: Mon, 18 May 2020 17:02:38 +0100 Subject: [PATCH] new config value: Security_SubMasters this is a CSV of avatar names that can issue commands like the master --- BSBshared/BotTypes/BasicBot.cs | 47 +++++++++++++++++++++++++---- BSBshared/Json/JsonConfig.cs | 1 + BSBshared/Json/JsonConfigApi.cs | 3 ++ CLI/Dockerfile-ForDebug | 2 ++ Core/bottypes/MessageSwitcherBot.cs | 7 +++-- Dockerfile | 2 ++ 6 files changed, 54 insertions(+), 8 deletions(-) diff --git a/BSBshared/BotTypes/BasicBot.cs b/BSBshared/BotTypes/BasicBot.cs index 744aea3..f56ab16 100644 --- a/BSBshared/BotTypes/BasicBot.cs +++ b/BSBshared/BotTypes/BasicBot.cs @@ -15,6 +15,18 @@ namespace BetterSecondBotShared.bottypes { LastStatusMessage = "No status"; } + protected List SubMasters = new List(); + public bool is_avatar_master(string name) + { + if (name == myconfig.Security_MasterUsername) + { + return true; + } + else + { + return SubMasters.Contains(name); + } + } protected bool killMe; protected JsonConfig myconfig; @@ -64,6 +76,21 @@ namespace BetterSecondBotShared.bottypes { bits.Add("Resident"); myconfig.Security_MasterUsername = String.Join(" ", bits); + + } + if (helpers.notempty(myconfig.Security_SubMasters) == true) + { + string[] master_names = myconfig.Security_SubMasters.Split(",", StringSplitOptions.RemoveEmptyEntries); + foreach (string a in master_names) + { + bits = a.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToList(); + if (bits.Count == 1) + { + bits.Add("Resident"); + } + SubMasters.Add(String.Join(" ", bits)); + ConsoleLog.Info("Sub-Master: " + myconfig.Security_MasterUsername); + } } ConsoleLog.Info("Build: " + version); } @@ -159,9 +186,17 @@ namespace BetterSecondBotShared.bottypes protected virtual void GroupInvite(InstantMessageEventArgs e) { - string[] stage1 = myconfig.Security_MasterUsername.ToLowerInvariant().Split(' '); - string bad_master_name = String.Join('.', stage1); - if (e.IM.FromAgentName == bad_master_name) + string[] stage1 = e.IM.FromAgentName.ToLowerInvariant().Split('.'); + string name = "" + stage1[0].FirstCharToUpper() + ""; + if (stage1.Length == 1) + { + name = " Resident"; + } + else + { + name = "" + name + " " + stage1[1].FirstCharToUpper() + ""; + } + if(is_avatar_master(name) == true) { GroupInvitationEventArgs G = new GroupInvitationEventArgs(e.Simulator, e.IM.FromAgentID, e.IM.FromAgentName, e.IM.Message); Client.Self.GroupInviteRespond(G.AgentID, e.IM.IMSessionID, true); @@ -170,7 +205,7 @@ namespace BetterSecondBotShared.bottypes } protected virtual void FriendshipOffer(UUID IMSessionID, string FromAgentName, UUID FromAgentID) { - if (FromAgentName == myconfig.Security_MasterUsername) + if (is_avatar_master(FromAgentName) == true) { Client.Friends.AcceptFriendship(FromAgentID, IMSessionID); } @@ -178,7 +213,7 @@ namespace BetterSecondBotShared.bottypes protected virtual void RequestLure(UUID IMSessionID, string FromAgentName, UUID FromAgentID) { - if (FromAgentName == myconfig.Security_MasterUsername) + if (is_avatar_master(FromAgentName) == true) { Client.Self.SendTeleportLure(FromAgentID); } @@ -196,7 +231,7 @@ namespace BetterSecondBotShared.bottypes protected virtual void RequestTeleport(UUID IMSessionID, string FromAgentName, UUID FromAgentID) { bool allow = false; - if (FromAgentName == myconfig.Security_MasterUsername) + if (is_avatar_master(FromAgentName) == true) { allow = true; } diff --git a/BSBshared/Json/JsonConfig.cs b/BSBshared/Json/JsonConfig.cs index ba906b1..52ca403 100644 --- a/BSBshared/Json/JsonConfig.cs +++ b/BSBshared/Json/JsonConfig.cs @@ -13,6 +13,7 @@ namespace BetterSecondBotShared.Json // Security public string Security_MasterUsername { get; set; } + public string Security_SubMasters { get; set; } public string Security_SignedCommandkey { get; set; } public string Security_WebUIKey { get; set; } diff --git a/BSBshared/Json/JsonConfigApi.cs b/BSBshared/Json/JsonConfigApi.cs index 76acb12..ed02722 100644 --- a/BSBshared/Json/JsonConfigApi.cs +++ b/BSBshared/Json/JsonConfigApi.cs @@ -26,6 +26,8 @@ namespace BetterSecondBotShared.Json else if (cmd == "Basic_HomeRegions") return "a CSV of SLURLs that the bot will attempt to return to after avoiding a sim shutdown (In testing)"; // Security else if (cmd == "Security_MasterUsername") return "The username of the bots owner *you can leave out Resident if you so wish*"; + else if (cmd == "Security_SubMasters") return "A CSV of avatar names who can issue commands to the bot"; + else if (cmd == "Security_SignedCommandkey") return "Used when sending the bot a HTTP or IM command that has a hash validation"; else if (cmd == "Security_WebUIKey") return "Used with the webUI to login, note: 2FA support is planned soon for this system that will replace this UIkey"; // Settings @@ -82,6 +84,7 @@ namespace BetterSecondBotShared.Json else if (cmd == "Basic_HomeRegions") return "http://maps.secondlife.com/secondlife/Viserion/50/140/23"; // Security else if (cmd == "Security_MasterUsername") return "Madpeter Zond"; + else if (cmd == "Security_SubMasters") return "Master Zond,Madpeter Zond,Madpeter Zond"; else if (cmd == "Security_SignedCommandkey") return "asdt234t34d3f34f"; else if (cmd == "Security_WebUIKey") return "2135r3y4vw232"; // Settings diff --git a/CLI/Dockerfile-ForDebug b/CLI/Dockerfile-ForDebug index a8192d8..0c4e35c 100644 --- a/CLI/Dockerfile-ForDebug +++ b/CLI/Dockerfile-ForDebug @@ -32,12 +32,14 @@ ENV Basic_HomeRegions='http://maps.secondlife.com/secondlife/Viserion/50/140/23' ENV Security_MasterUsername='Madpeter Zond' ENV Security_SignedCommandkey='' ENV Security_WebUIKey='' +ENV Security_SubMasters='X X,Y Y,Z Z' ENV Setting_AllowRLV='false' ENV Setting_AllowFunds='false' ENV Setting_LogCommands='true' ENV Setting_RelayImToAvatarUUID='' ENV Setting_DefaultSit_UUID='' +ENV Setting_loginURI='secondlife' ENV DiscordRelay_URL='' ENV DiscordRelay_GroupUUID='' diff --git a/Core/bottypes/MessageSwitcherBot.cs b/Core/bottypes/MessageSwitcherBot.cs index 213edce..c7cf264 100644 --- a/Core/bottypes/MessageSwitcherBot.cs +++ b/Core/bottypes/MessageSwitcherBot.cs @@ -104,9 +104,12 @@ namespace BSB.bottypes { CoreCommandLib(sender_uuid, false, bits.ElementAt(0), bits.ElementAt(1), signing_code, arg_signed_with); } - else if (myconfig.Security_MasterUsername == sender_name) + else { - CoreCommandLib(sender_uuid, true, bits.ElementAt(0), bits.ElementAt(1), "", arg_signed_with); + if (is_avatar_master(sender_name) == true) + { + CoreCommandLib(sender_uuid, true, bits.ElementAt(0), bits.ElementAt(1), "", arg_signed_with); + } } } } diff --git a/Dockerfile b/Dockerfile index 2d47fd4..f258874 100644 --- a/Dockerfile +++ b/Dockerfile @@ -30,6 +30,7 @@ ENV Basic_BotPassword='' ENV Basic_HomeRegions='http://maps.secondlife.com/secondlife/Viserion/50/140/23' ENV Security_MasterUsername='Madpeter Zond' +ENV Security_SubMasters='X X,Y Y,Z Z' ENV Security_SignedCommandkey='' ENV Security_WebUIKey='' @@ -38,6 +39,7 @@ ENV Setting_AllowFunds='false' ENV Setting_LogCommands='true' ENV Setting_RelayImToAvatarUUID='' ENV Setting_DefaultSit_UUID='' +ENV Setting_loginURI='secondlife' ENV DiscordRelay_URL='' ENV DiscordRelay_GroupUUID=''