more updates

This commit is contained in:
Zontreck 2020-04-20 01:42:08 -07:00
parent 504a66f807
commit 80f536bfe9
7 changed files with 306 additions and 11 deletions

View file

@ -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

127
CommandSystem/BaseHooks.cs Normal file
View file

@ -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<string> arguments, string body, string method, NameValueCollection headers)
{
WebhookRegistry.HTTPResponseData httpReply = new WebhookRegistry.HTTPResponseData();
CommandRegistry reg = CommandRegistry.Instance;
string Final = "<body bgcolor='black'><style type='text/css'>table.HelpTable { border: 5px solid #1C6EA4;" +
" background - color: #000000; " +
" width: 100 %; text - align: left; border - collapse: collapse;" +
" } table.HelpTable td, table.HelpTable th { border: 3px solid #AAAAAA;" +
" padding: 3px 2px; } table.HelpTable tbody td { font-size: 19px; color: #69FAF7;" +
"} table.HelpTable tr:nth-child(even) { background: #000000;} table.HelpTable thead" +
" { background: #26A486; background: -moz-linear-gradient(top, #5cbba4 0%, #3bad92 66%, #26A486 100%);" +
" background: -webkit-linear-gradient(top, #5cbba4 0%, #3bad92 66%, #26A486 100%);" +
" background: linear-gradient(to bottom, #5cbba4 0%, #3bad92 66%, #26A486 100%);" +
" border-bottom: 2px solid #444444;} table.HelpTable thead th { font-size: 25px;" +
" font-weight: bold; color: #FFFFFF; text-align: center; border-left: 2px solid #D0E4F5;" +
"}table.HelpTable thead th:first-child { border-left: none;}table.HelpTable tfoot td { font-size: 14px;" +
"}table.HelpTable tfoot.links{ text-align: right;}table.HelpTable tfoot.links a{display: inline - block;" +
"background: #1C6EA4; color: #FFFFFF; padding: 2px 8px; border - radius: 5px;}</style>";
Final += "<table class='HelpTable'><thead><tr><th>Bot Version</th><th>5</th></tr></table><br/>";
Final += "<table class='HelpTable'><thead><tr><th>Command</th><th>Minimum Level Required</th><th>Usage</th><th>Allowed Sources</th><th>Number of Arguments required</th></thead><tbody>";
foreach (KeyValuePair<string, CommandGroup> cmd in reg.Cmds)
{
// Command
Final += "<tr><td>" + cmd.Value.Command + "</td>";
// Level
Final += "<td>" + cmd.Value.minLevel.ToString() + "</td>";
// Usage
Final += "<td>" + cmd.Value.cmdUsage.RawUsage() + "</td>";
// Allowed Sources
Final += "<td>" + cmd.Value.CommandSource + "</td>";
// # Arguments
Final += "<td>" + cmd.Value.arguments.ToString() + "</td></tr>";
}
Final += "</tbody></table>";
Final += "<table class='HelpTable'><thead><tr><th>Hook Path</th><tr></thead><tbody>";
WebhookRegistry regx = WebhookRegistry.Instance;
foreach(KeyValuePair<string, WebhookAttribs> hooks in regx.hooks)
{
Final += "<tr><td>" + hooks.Value.Path + "</td></tr>";
}
Final += "</tbody></table>";
Final += "<br/><table class='HelpTable'><thead><tr><th>Assembly</th><th>Version</th><th># Of Commands</th><th>Total Classes</th></tr></thead><tbody>";
foreach (Assembly A in AppDomain.CurrentDomain.GetAssemblies())
{
Final += "<tr><td>" + A.GetName().Name + "</td><td>" + A.GetName().Version + "</td>";
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 += "<td>" + TotalCommandsContained.ToString() + "</td><td>" + TotalClasses.ToString() + "</td></tr>";
}
Final += "</tbody></table>";
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());
}
}
}
}

View file

@ -59,6 +59,14 @@ namespace Bot
public Dictionary<UUID, int> BotAdmins { get; set; } = new Dictionary<UUID, int>();
public List<string> AuthedGithubUsers { get; set; } = new List<string>();
public List<string> LinkedDLLs { get; set; } = new List<string>();
public bool Authed(string GHLogin)
{
if (AuthedGithubUsers.Contains(GHLogin)) return true;
else return false;
}
public void Load()
{

62
Level System/Auth.cs Normal file
View file

@ -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();
}
}
}

View file

@ -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<IProgram> Activate(Assembly asm)

View file

@ -375,25 +375,46 @@ namespace Bot
{
int programCount = 0;
PluginActivator PA = new PluginActivator();
PA.LoadLibrary(conf.MainProgramDLL);
Assembly MainProg = PA.LoadLibrary(conf.MainProgramDLL);
List<IProgram> plugins = PA.Activate(PA.LoadedASM);
Dictionary<IProgram, Assembly> plugins = new Dictionary<IProgram, Assembly>();
List<IProgram> plg1 = PA.Activate(MainProg);
List<IProgram> mainExe = PA.Activate(_s);
foreach(string DLL in MainConfiguration.Instance.LinkedDLLs)
{
Assembly DLLID = PA.LoadLibrary(DLL+".dll");
List<IProgram> 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<IProgram, Assembly> 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<string, string> cmd = new Dictionary<string, string>();
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)
{

View file

@ -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();
}
}
}