예제 #1
0
 public BetterAtHome(Cli setcontroler, JsonConfig configfile)
 {
     controler       = setcontroler;
     this.configfile = configfile;
     attach_events();
     SetBetterAtHomeAction("Standby");
     foreach (string a in configfile.Basic_HomeRegions)
     {
         string[] bits = helpers.ParseSLurl(a);
         homeRegions.Add(bits[0]);
         LogFormater.Info("Added home region: " + bits[0]);
     }
     if (configfile.Basic_AvoidRestartRegions != null)
     {
         foreach (string a in configfile.Basic_AvoidRestartRegions)
         {
             string[] bits = helpers.ParseSLurl(a);
             avoidRestartRegions.Add(bits[0]);
             LogFormater.Info("Added restart region: " + bits[0]);
         }
     }
     else
     {
         LogFormater.Warn("Config is old - please update");
     }
 }
예제 #2
0
        public Cli(JsonConfig Config, bool as_docker, bool use_self_keep_alive, string loadingFromFolder)
        {
            exitBot    = false;
            use_folder = loadingFromFolder;
            LogFormater.Info("Starting cli");
            if (helpers.botRequired(Config) == true)
            {
                Bot = new SecondBot();
                Bot.setFolder(use_folder);
                Bot.Setup(Config, AssemblyInfo.GetGitHash());

                if (as_docker == true)
                {
                    Bot.AsDocker();
                }

                Bot.Start(false);

                attachEventListenerObjects(Config, as_docker);
                if (use_self_keep_alive == true)
                {
                    keep_alive();
                }
            }
            else
            {
                LogFormater.Warn("Required settings missing");
            }
            if (use_self_keep_alive == true)
            {
                exitBot = true;
            }
        }
예제 #3
0
 protected void SetPropTypeAndValue(JsonConfig reply, PropertyInfo prop, string arg, string arg_type, string arg_value_default)
 {
     if (prop != null)
     {
         if (prop.CanWrite == true)
         {
             if (arg_type == "Number")
             {
                 if (int.TryParse(arg_value_default, out int result) == true)
                 {
                     prop.SetValue(reply, result, null);
                 }
             }
             else if (arg_type == "Text")
             {
                 prop.SetValue(reply, arg_value_default, null);
             }
             else if (arg_type == "True|False")
             {
                 if (bool.TryParse(arg_value_default, out bool result) == true)
                 {
                     prop.SetValue(reply, result, null);
                 }
             }
             else if (arg_type == "Collection")
             {
                 prop.SetValue(reply, arg_value_default.Split(','), null);
             }
             else if (arg_type == "BigNumber")
             {
                 if (ulong.TryParse(arg_value_default, out ulong result) == true)
                 {
                     prop.SetValue(reply, result, null);
                 }
             }
             else if (arg_type == "Float")
             {
                 if (float.TryParse(arg_value_default, out float result) == true)
                 {
                     prop.SetValue(reply, result, null);
                 }
             }
             else
             {
                 LogFormater.Debug("unsupported arg_type: " + arg_type + " for " + arg + "");
             }
         }
         else
         {
             LogFormater.Warn("Unable to write to " + arg + "");
         }
     }
     else
     {
         LogFormater.Crit("unknown prop " + arg + "");
     }
 }
예제 #4
0
        public object SetParcelFlag([FormField] string escapedflagdata, string token)
        {
            KeyValuePair <bool, string> tests = SetupCurrentParcel(token, "parcel", "SetParcelFlag");

            if (tests.Key == false)
            {
                return(Failure(tests.Value, "SetParcelFlag", new [] { escapedflagdata }));
            }
            List <string> acceptablewords          = new List <string>();
            Dictionary <string, ParcelFlags> flags = parcel_static.get_flags_list();

            acceptablewords.AddRange(new[] { "True", "False" });

            Dictionary <string, bool> setflags = new Dictionary <string, bool>();

            string[] args = escapedflagdata.Split(":::");
            foreach (string a in args)
            {
                string[] parts = a.Split('=', StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length != 2)
                {
                    LogFormater.Warn("Flag: " + a + " missing \"=\"");
                    continue;
                }
                if (flags.ContainsKey(parts[0]) == false)
                {
                    LogFormater.Warn("Flag: " + parts[0] + " is unknown");
                    continue;
                }
                if (acceptablewords.Contains(parts[1]) == false)
                {
                    LogFormater.Crit("Unable to set flag " + parts[0] + " to : " + parts[1] + "");
                }
                setflags.Add(parts[0], Convert.ToBoolean(parts[1]));
            }
            if (setflags.Count == 0)
            {
                return(Failure("No accepted flags", "SetParcelFlag", new [] { escapedflagdata }));
            }
            if (parcel_static.has_parcel_perm(targetparcel, bot) == false)
            {
                return(Failure("Incorrect perms to control parcel", "SetParcelFlag", new [] { escapedflagdata }));
            }
            foreach (KeyValuePair <string, bool> cfg in setflags)
            {
                if (flags.ContainsKey(cfg.Key) == true)
                {
                    parcel_static.ParcelSetFlag(flags[cfg.Key], targetparcel, cfg.Value);
                }
            }
            targetparcel.Update(bot.GetClient.Network.CurrentSim, false);
            return(BasicReply("Applying perms", "SetParcelFlag", new [] { escapedflagdata }));
        }
예제 #5
0
 public static bool botRequired(JsonConfig test)
 {
     if (helpers.notempty(test.Basic_BotUserName) && helpers.notempty(test.Basic_BotPassword) && helpers.notempty(test.Security_MasterUsername) && helpers.notempty(test.Security_SignedCommandkey))
     {
         // required values are set
         MakeJsonConfig Testing             = new MakeJsonConfig();
         string[]       testingfor          = new[] { "Basic_BotUserName", "Basic_BotPassword", "Security_SignedCommandkey", "Security_WebUIKey" };
         bool           default_value_found = false;
         foreach (string a in testingfor)
         {
             if (Testing.GetCommandArgTypes(a).First() == MakeJsonConfig.GetProp(test, a))
             {
                 LogFormater.Warn("" + a + " is currently set to the default");
                 default_value_found = true;
                 break;
             }
         }
         if (default_value_found == false)
         {
             LogFormater.Status("User => " + test.Basic_BotUserName);
             LogFormater.Status("Master => " + test.Security_MasterUsername);
         }
         return(!default_value_found);
     }
     else
     {
         if (helpers.notempty(test.Basic_BotUserName) == false)
         {
             LogFormater.Warn("Basic_BotUserName is null or empty");
         }
         if (helpers.notempty(test.Basic_BotPassword) == false)
         {
             LogFormater.Warn("Basic_BotPassword is null or empty");
         }
         if (helpers.notempty(test.Security_MasterUsername) == false)
         {
             LogFormater.Warn("Security_MasterUsername is null or empty");
         }
         if (helpers.notempty(test.Security_SignedCommandkey) == false)
         {
             LogFormater.Warn("Security_SignedCommandkey is null or empty");
         }
         return(false);
     }
 }
예제 #6
0
 public static JsonConfig Http_config_check(JsonConfig jsonConfig)
 {
     if (helpers.notempty(jsonConfig.Security_WebUIKey) == true)
     {
         if (helpers.notempty(jsonConfig.Http_Host) == true)
         {
             if (jsonConfig.Http_Enable == true)
             {
                 jsonConfig.Http_Enable = false;
                 if (jsonConfig.Security_WebUIKey.Length < 12)
                 {
                     LogFormater.Warn("Http disabled: Security_WebUIKey length must be 12 or more");
                 }
                 else if ((jsonConfig.Http_Host != "docker") && (jsonConfig.Http_Host.StartsWith("http") == false))
                 {
                     LogFormater.Warn("Http disabled: Http_Host must be vaild or \"docker\" - Given: (" + jsonConfig.Http_Host + ")");
                 }
                 else
                 {
                     if (jsonConfig.Http_Host == "docker")
                     {
                         jsonConfig.Http_Host = "http://*:80";
                     }
                     jsonConfig.Http_Enable = true;
                 }
             }
             else
             {
                 LogFormater.Info("Http interface disabled by config");
             }
         }
         else
         {
             LogFormater.Warn("Http disabled: Http_Host is null");
             jsonConfig.Http_Enable = false;
         }
     }
     else
     {
         LogFormater.Warn("Http disabled: Security_WebUIKey is null");
         jsonConfig.Http_Enable = false;
     }
     return(jsonConfig);
 }
예제 #7
0
        protected void processScopedTokenRaw(string raw)
        {
            raw = raw.Replace(" ", "");
            string[]        bits      = raw.Split(',');
            string          code      = null;
            int             accessids = 0;
            scopedTokenInfo stinfo    = new scopedTokenInfo();

            foreach (string bit in bits)
            {
                string[] subbits = bit.Split(':');
                if (subbits[0] == "t")
                {
                    code = subbits[1];
                }
                else if (subbits[0] == "cm")
                {
                    stinfo.AllowCommands.Add(subbits[1]);
                    accessids++;
                }
                else if (subbits[0] == "cg")
                {
                    stinfo.AllowAccessGroups.Add(subbits[1]);
                    accessids++;
                }
                else if (subbits[0] == "ws")
                {
                    stinfo.AllowWorkgroups.Add(subbits[1]);
                    accessids++;
                }
            }
            if ((code != null) && (accessids > 0))
            {
                Tokens.AddScopedToken(code, stinfo);
                LogFormater.Info("Adding scopped command " + code + " with: " + accessids.ToString() + " access types");
            }
            else
            {
                LogFormater.Warn("Scoped access code: " + raw + " did not pass checks");
            }
        }
예제 #8
0
        protected bool whereChecks(OnEvent E, Dictionary <string, string> args, bool enableCronArgs = false)
        {
            bool WherePassed = true;

            Dictionary <string, string> updateArgs = new Dictionary <string, string>();

            string[] keys = args.Keys.ToArray();
            foreach (string K in keys)
            {
                args[K] = args[K].Trim();
            }
            List <string> WhereFilters = new List <string>()
            {
                "CRON", "IN_GROUP", "NOT_IN_GROUP",
                "IS", "NOT", "IS_EMPTY", "HAS", "MISSING",
                "IS_UUID", "CRON", "LOCKOUT"
            };

            foreach (string A in E.Where)
            {
                if ((A.Contains(" {CRON} ") == true) && (enableCronArgs == false))
                {
                    WherePassed = false;
                    break;
                }
                List <string> bits   = new List <string>();
                string        filter = "";
                foreach (string F in WhereFilters)
                {
                    if (A.Contains(" {" + F + "} ") == true)
                    {
                        filter = F;
                        bits   = A.Split(" {" + F + "} ", StringSplitOptions.None).ToList();
                        break;
                    }
                }
                if (filter == "")
                {
                    WherePassed = false;
                    break;
                }
                if (bits.Count != 2)
                {
                    WherePassed = false;
                    break;
                }
                bits[0] = bits[0].Trim();
                bits[1] = bits[1].Trim();
                bits[0] = UpdateBits(bits[0], args);
                bits[1] = UpdateBits(bits[1], args);
                if (filter == "CRON")
                {
                    if (cronMagic(bits[0], bits[1]) == false)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn(WhyCronFailed, true);
                        }
                        WherePassed = false;
                        break;
                    }
                }
                else if (filter == "LOCKOUT")
                {
                    if (bool.TryParse(bits[1], out bool status) == false)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{LOCKOUT} Unable to unpack settings for right flag", true);
                        }
                        WherePassed = false;
                        break;
                    }
                    if (UUID.TryParse(bits[0], out UUID leftUUID) == false)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{LOCKOUT} Unable to unpack settings for left UUID", true);
                        }
                        WherePassed = false;
                        break;
                    }
                    bool check = Lockout.ContainsKey(leftUUID);
                    if (check != status)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{LOCKOUT} Expected right flag does not match check", true);
                        }
                        WherePassed = false;
                        break;
                    }
                }
                else if (filter == "IS")
                {
                    if (bits[0] != bits[1])
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{IS} " + bits[0] + " != " + bits[1] + "", true);
                        }
                        WherePassed = false;
                        break;
                    }
                }
                else if (filter == "NOT")
                {
                    if (bits[0] == bits[1])
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{NOT} " + bits[0] + " == " + bits[1] + "", true);
                        }
                        WherePassed = false;
                        break;
                    }
                }
                else if (filter == "IS_EMPTY")
                {
                    if (bool.TryParse(bits[1], out bool status) == false)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{IS_EMPTY} unable to unpack right flag", true);
                        }
                        WherePassed = false;
                        break;
                    }
                    bool check = false;
                    if (bits[0].Length == 0)
                    {
                        check = true;
                    }
                    if (check != status)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{IS_EMPTY} " + bits[0] + " " + bits[1] + "", true);
                        }
                        WherePassed = false;
                        break;
                    }
                }
                else if (filter == "HAS")
                {
                    if (bits[0].Contains(bits[1]) == false)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{HAS} " + bits[0] + " does not contain " + bits[1] + "", true);
                        }
                        WherePassed = false;
                        break;
                    }
                }
                else if (filter == "MISSING")
                {
                    if (bits[0].Contains(bits[1]) == true)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{MISSING} " + bits[0] + " does contain " + bits[1] + "", true);
                        }
                        WherePassed = false;
                        break;
                    }
                }
                else if (filter == "IS_UUID")
                {
                    if (bool.TryParse(bits[1], out bool resultCheck) == false)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{IS_UUID} " + bits[1] + " unable to unpack", true);
                        }
                        WherePassed = false;
                        break;
                    }
                    bool isUUID = UUID.TryParse(bits[0], out UUID _);
                    if (resultCheck != isUUID)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{IS_UUID} " + bits[0] + " failed UUID check result " + bits[1], true);
                        }
                        WherePassed = false;
                        break;
                    }
                }
                else if ((filter == "IN_GROUP") || (filter == "NOT_IN_GROUP"))
                {
                    bool expectedStatus = true;
                    if (filter == "NOT_IN_GROUP")
                    {
                        expectedStatus = false;
                    }
                    if (UUID.TryParse(bits[0], out UUID avatar) == false)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{" + filter + "} " + bits[0] + " unable to unpack avatar UUID", true);
                        }
                        WherePassed = false;
                        break;
                    }
                    if (UUID.TryParse(bits[1], out UUID group) == false)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{" + filter + "} " + bits[1] + " unable to unpack group UUID", true);
                        }
                        WherePassed = false;
                        break;
                    }
                    if (GroupMembership.ContainsKey(group) == false)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{" + filter + "} GroupMembership does not have group: " + bits[1], true);
                        }
                        WherePassed = false;
                        break;
                    }
                    bool status = GroupMembership[group].Contains(avatar);
                    if (status != expectedStatus)
                    {
                        if (DebugWhere == true)
                        {
                            LogFormater.Warn("{" + filter + "} Failed checks", true);
                        }
                        WherePassed = false;
                        break;
                    }
                }
            }

            return(WherePassed);
        }
예제 #9
0
 public virtual void Warn(string message)
 {
     Log2File(LogFormater.Warn(message, false), ConsoleLogLogLevel.Warn);
 }
예제 #10
0
        public CliHardware(string[] args)
        {
            SimpleIO   io         = new SimpleIO();
            JsonConfig Config     = new JsonConfig();
            string     loadFolder = "debug";
            string     json_file  = "bot.json";

#if DEBUG
            LogFormater.Debug("!! RUNNING IN DEBUG !!");
#else
            LogFormater.Status("Hardware config");
            if (args.Length == 1)
            {
                loadFolder = args[0];
            }
            else
            {
                loadFolder = "default";
                io.ChangeRoot("default");
                LogFormater.Warn("Using: using default folder");
            }
#endif
            io.ChangeRoot(loadFolder);
            if (SimpleIO.DirExists("wiki") == false)
            {
                LogFormater.Info("Basic Wiki [Creating]");
                new DebugModeCreateWiki(AssemblyInfo.GetGitHash(), io);
                LogFormater.Info("Basic Wiki [Ready]");
                io = new SimpleIO();
            }
            bool ok_to_try_start = false;
            if (SimpleIO.FileType(json_file, "json") == true)
            {
                if (io.Exists(json_file))
                {
                    string json = io.ReadFile(json_file);
                    if (json.Length > 0)
                    {
                        try
                        {
                            Config          = JsonConvert.DeserializeObject <JsonConfig>(json);
                            ok_to_try_start = true;
                        }
                        catch (Exception e)
                        {
                            LogFormater.Warn("Unable to read config file\n moving config to " + json_file + ".old and creating a empty config\nError was: " + e.Message + "");
                            io.MarkOld(json_file);
                            Config = new JsonConfig();
                            io.WriteJsonConfig(MakeJsonConfig.GetDefault(), json_file);
                        }
                    }
                    else
                    {
                        LogFormater.Warn("Json config is empty creating an empty one for you");
                        io.WriteJsonConfig(MakeJsonConfig.GetDefault(), json_file);
                    }
                }
                else
                {
                    LogFormater.Warn("Json config does not Exist creating it for you");
                    io.WriteJsonConfig(MakeJsonConfig.GetDefault(), json_file);
                }
            }
            else
            {
                LogFormater.Crit("you must select a .json file for config! example \"BetterSecondBot.exe mybot\" will use the mybot.json file!");
            }
            if (ok_to_try_start == true)
            {
                Config = MakeJsonConfig.Http_config_check(Config);
                new Discord_super(Config, false, loadFolder);
            }
        }