diff --git a/Assembly/ASMInfo.cs b/Assembly/ASMInfo.cs index 7c30401..4c1581e 100644 --- a/Assembly/ASMInfo.cs +++ b/Assembly/ASMInfo.cs @@ -6,7 +6,7 @@ using System.Reflection; [assembly: AssemblyCompany("ZNI")] [assembly: AssemblyAlgorithmId(System.Configuration.Assemblies.AssemblyHashAlgorithm.MD5)] [assembly: AssemblyCopyright("© 2020 Tara Piccari")] -[assembly: AssemblyFileVersion("5.513")] +[assembly: AssemblyFileVersion("5.586")] [assembly: AssemblyDescription("Second Life Bot - BotCore5")] @@ -15,7 +15,7 @@ namespace Bot.Assemble public class ASMInfo { public static string BotName = "ZBotCore"; - public static double BotVer = 5.513; + public static double BotVer = 5.586; public static string GitPassword { get diff --git a/CommandSystem/BaseHooks.cs b/CommandSystem/BaseHooks.cs new file mode 100644 index 0000000..623e55b --- /dev/null +++ b/CommandSystem/BaseHooks.cs @@ -0,0 +1,127 @@ +using Bot.Assemble; +using Bot.WebHookServer; +using OpenMetaverse; +using System; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace Bot.CommandSystem +{ + class BaseHooks + { + + [WebhookAttribs("/help")] + public WebhookRegistry.HTTPResponseData showHelp(List arguments, string body, string method, NameValueCollection headers) + { + WebhookRegistry.HTTPResponseData httpReply = new WebhookRegistry.HTTPResponseData(); + CommandRegistry reg = CommandRegistry.Instance; + + string Final = ""; + + Final += "
Bot Version5

"; + + Final += ""; + foreach (KeyValuePair cmd in reg.Cmds) + { + // Command + Final += ""; + // Level + Final += ""; + // Usage + Final += ""; + // Allowed Sources + Final += ""; + // # Arguments + Final += ""; + } + Final += "
CommandMinimum Level RequiredUsageAllowed SourcesNumber of Arguments required
" + cmd.Value.Command + "" + cmd.Value.minLevel.ToString() + "" + cmd.Value.cmdUsage.RawUsage() + "" + cmd.Value.CommandSource + "" + cmd.Value.arguments.ToString() + "
"; + + Final += ""; + WebhookRegistry regx = WebhookRegistry.Instance; + foreach(KeyValuePair hooks in regx.hooks) + { + Final += ""; + } + Final += "
Hook Path
" + hooks.Value.Path + "
"; + + Final += "
"; + + foreach (Assembly A in AppDomain.CurrentDomain.GetAssemblies()) + { + Final += ""; + int TotalCommandsContained = 0; + int TotalClasses = 0; + foreach (Type T in A.GetTypes()) + { + if (T.IsClass) + { + TotalClasses++; + foreach (MethodInfo MI in T.GetMethods()) + { + CommandGroup[] CG = (CommandGroup[])MI.GetCustomAttributes(typeof(CommandGroup), false); + TotalCommandsContained += CG.Length; + } + } + } + + Final += ""; + } + Final += "
AssemblyVersion# Of CommandsTotal Classes
" + A.GetName().Name + "" + A.GetName().Version + "" + TotalCommandsContained.ToString() + "" + TotalClasses.ToString() + "
"; + + + httpReply.ReplyString = Final; + httpReply.Status = 200; + httpReply.ReturnContentType = "text/html"; + + return httpReply; + } + + + + [CommandGroup("show_level", 0, 0, "This command shows your current auth level if any.", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_GROUP)] + public void show_level(UUID client, int level, GridClient grid, string[] additionalArgs, + MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, + CommandRegistry registry, UUID agentKey, string agentName) + { + MHE(source, client, "Hi secondlife:///app/agent/" + agentKey.ToString() + "/about !! Your authorization level is " + level.ToString()); + } + + [CommandGroup("show_version", 0, 0, "Outputs the bot version", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL)] + public void show_version(UUID client, int level, GridClient grid, string[] additionalArgs, + MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, + CommandRegistry registry, UUID agentKey, string agentName) + { + MHE(source, client, "Version " + ASMInfo.BotVer.ToString()); + } + + + + [CommandGroup("show_admins", 4, 0, "Outputs all admin users", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL)] + public void show_admins(UUID client, int level, GridClient grid, string[] additionalArgs, + MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, + CommandRegistry registry, UUID agentKey, string agentName) + { + + for (int i = 0; i < MainConfiguration.Instance.BotAdmins.Count; i++) + { + MHE(source, client, "secondlife:///app/agent/" + MainConfiguration.Instance.BotAdmins.ElementAt(i).Key.ToString() + "/about [" + MainConfiguration.Instance.BotAdmins.ElementAt(i).Value.ToString() + "] " + MainConfiguration.Instance.BotAdmins.ElementAt(i).Key.ToString()); + } + } + } +} diff --git a/ConfigSystem/MainConfiguration.cs b/ConfigSystem/MainConfiguration.cs index 5921b18..23fa2aa 100644 --- a/ConfigSystem/MainConfiguration.cs +++ b/ConfigSystem/MainConfiguration.cs @@ -59,6 +59,14 @@ namespace Bot public Dictionary BotAdmins { get; set; } = new Dictionary(); + public List AuthedGithubUsers { get; set; } = new List(); + public List LinkedDLLs { get; set; } = new List(); + + public bool Authed(string GHLogin) + { + if (AuthedGithubUsers.Contains(GHLogin)) return true; + else return false; + } public void Load() { diff --git a/Level System/Auth.cs b/Level System/Auth.cs new file mode 100644 index 0000000..a05abe8 --- /dev/null +++ b/Level System/Auth.cs @@ -0,0 +1,62 @@ +/* + +Copyright © 2019 Tara Piccari (Aria; Tashia Redrose) +Licensed under the GPLv2 + +*/ + +using OpenMetaverse; +using Bot; +using Bot.CommandSystem; + + + +namespace Bot +{ + class Auth + { + + [CommandGroup("auth_user", 5, 2, "Authorizes a user to have command access. Arguments are user (UUID), and Level (int)", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL)] + public void set_auth(UUID client, int level, GridClient grid, string[] additionalArgs, + MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, + CommandRegistry registry, UUID agentKey, string agentName) + { + MainConfiguration mem = MainConfiguration.Instance; + BotSession.Instance.Logger.info(log:"Existing Admins: " + mem.BotAdmins.Count.ToString()); + if (level < 5 && mem.BotAdmins.Count > 0) + { + MHE(source, UUID.Zero, "Authorization failure. You do not have the proper permission level"); + //grid.Self.Chat(, 0, ChatType.Normal); + return; + } + MHE(source, UUID.Zero, "Authorizing.."); + //grid.Self.Chat("Authorizing user..", 0, ChatType.Normal); + UUID user = UUID.Parse(additionalArgs[0]); + int NewLevel = int.Parse(additionalArgs[1]); + if (NewLevel <= 0) + { + mem.BotAdmins.Remove(user); + MHE(MessageHandler.Destinations.DEST_AGENT, user, "Your access to the main bot has been removed. You will still have access to any command that does not require a access level higher than 0"); + MHE(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "Access Removed"); + mem.Save(); + return; + } + + if (NewLevel > level && mem.BotAdmins.Count > 0) + { + MHE(source, client, "Cannot authorize higher than your own level"); + return; + } + + + if (!mem.BotAdmins.ContainsKey(user)) + mem.BotAdmins.Add(user, NewLevel); + else + mem.BotAdmins[user] = NewLevel; + MHE(MessageHandler.Destinations.DEST_AGENT, user, "You have been granted authorization level " + NewLevel.ToString()); + MHE(source, UUID.Zero, "Authorized"); + mem.Save(); + + } + } +} diff --git a/PluginActivator.cs b/PluginActivator.cs index bea258f..cbc1dec 100644 --- a/PluginActivator.cs +++ b/PluginActivator.cs @@ -10,10 +10,12 @@ namespace Bot public class PluginActivator { public Assembly LoadedASM = null; - public void LoadLibrary(string DLL) + + public Assembly LoadLibrary(string DLL) { LoadedASM = Assembly.LoadFrom(DLL); + return LoadedASM; } public List Activate(Assembly asm) diff --git a/Program.cs b/Program.cs index 565dee1..469f370 100644 --- a/Program.cs +++ b/Program.cs @@ -375,25 +375,46 @@ namespace Bot { int programCount = 0; PluginActivator PA = new PluginActivator(); - PA.LoadLibrary(conf.MainProgramDLL); - - List plugins = PA.Activate(PA.LoadedASM); + Assembly MainProg = PA.LoadLibrary(conf.MainProgramDLL); + + Dictionary plugins = new Dictionary(); + List plg1 = PA.Activate(MainProg); List mainExe = PA.Activate(_s); + foreach(string DLL in MainConfiguration.Instance.LinkedDLLs) + { + Assembly DLLID = PA.LoadLibrary(DLL+".dll"); + List progs = PA.Activate(DLLID); + int vx = 0; + foreach(IProgram prog in progs) + { + vx++; + plugins.Add(prog, DLLID); + } + + msg(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, $"Plugin loaded: {DLL}.dll, {vx} threads"); + + } + + foreach(IProgram plug in plg1) + { + plugins.Add(plug, MainProg); + } + foreach(IProgram plug in mainExe) { - plugins.Add(plug); + plugins.Add(plug, _s); } - foreach (IProgram plugin in plugins) + foreach (KeyValuePair pluginKvp in plugins) { - + IProgram plugin = pluginKvp.Key; plugin.run(client, MH, registry); // simulate constructor and set up other things g_ZPrograms.Add(plugin); client.Self.IM += plugin.onIMEvent; programCount++; - Log.info(true, "Plugin: " + plugin.ProgramName + " [" + PA.LoadedASM.FullName + "] added to g_ZPrograms"); + Log.info(true, "Plugin: " + plugin.ProgramName + " [" + pluginKvp.Value.FullName + "] added to g_ZPrograms"); if (File.Exists(plugin.ProgramName + ".json")) plugin.LoadConfiguration(); // will throw an error if BlankBot tries to load config } @@ -622,6 +643,42 @@ namespace Bot */ } + [CommandGroup("load_dll", 5, 1, "load_dll [DLL_Name] - Loads a DLL and searches for entry points", MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_AGENT)] + public void load_DLL(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName) + { + // Load DLL + MainConfiguration cfg = MainConfiguration.Instance; + + cfg.LinkedDLLs.Add(additionalArgs[0]); + Dictionary cmd = new Dictionary(); + cmd.Add("type", "load_program"); + cmd.Add("newProgram", additionalArgs[0]); + string strCmd = JsonConvert.SerializeObject(cmd); + MHE(MessageHandler.Destinations.DEST_ACTION, UUID.Zero, strCmd); + + cfg.Save(); + } + + + [CommandGroup("unload_dll", 5, 1, "unload_dll [DLL_Name] - Prevents DLL from reloading at next reboot", MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_AGENT)] + public void unload_DLL(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName) + { + // Load DLL + MainConfiguration cfg = MainConfiguration.Instance; + + cfg.LinkedDLLs.Remove(additionalArgs[0]); + + MHE(MessageHandler.Destinations.DEST_LOCAL, UUID.Zero, "DLL marked for unload at next bot restart"); + + cfg.Save(); + } + + [CommandGroup("assign", 75, 1, "assign [DLL Name] - Sets the active DLL", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL)] + public void SetActiveProgram(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName) + { + MHE(MessageHandler.Destinations.DEST_ACTION, UUID.Zero, "{\"type\":\"assignProgram\",\"newProgram\":\"" + additionalArgs[0] + "\"}"); + } + [STAThread()] private static void onObjectTerseUpdate(object sender, TerseObjectUpdateEventArgs e) { diff --git a/WebHookServer/HookCmds.cs b/WebHookServer/HookCmds.cs index 54eb3a0..79da196 100644 --- a/WebHookServer/HookCmds.cs +++ b/WebHookServer/HookCmds.cs @@ -1,4 +1,6 @@ -using System; +using Bot.CommandSystem; +using OpenMetaverse; +using System; using System.Collections.Generic; using System.IO; using System.Net; @@ -54,5 +56,42 @@ namespace Bot.WebHookServer output.Close(); } + + + [CommandGroup("webhook_auth", 4, 2, "webhook_auth [github_name] [y/n]", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_GROUP)] + public void WebHookAuthMgr(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName) + { + MainConfiguration cfg = MainConfiguration.Instance; + + MHE(source, client, "Checking.."); + + if (cfg.Authed(additionalArgs[0])) + { + if (additionalArgs[1] == "y") + { + MHE(source, client, "Not modified. Already authorized"); + } + else + { + MHE(source, client, "Authorization revoked - git alerts from this user will not be whitelisted"); + cfg.AuthedGithubUsers.Remove(additionalArgs[0]); + } + } + else + { + if (additionalArgs[1] == "y") + { + cfg.AuthedGithubUsers.Add(additionalArgs[0]); + MHE(source, client, "Authorized."); + } + else + { + MHE(source, client, "Not modified. Already not whitelisted"); + } + } + + + cfg.Save(); + } } }