Ejemplo n.º 1
0
        /// <summary>
        /// 设置配置值
        /// </summary>
        /// <param name="conf"></param>
        /// <param name="tenantId"></param>
        /// <param name="value"></param>
        public static void SetConfig(Configs conf, int tenantId, object value)
        {
            string val;

            if (value == null)
            {
                val = "";
            }
            else
            {
                val = value.ToString();
            }
            var sqlwhere = "Sys_Config.ConfigName=@name AND Sys_Config.TenantId=@tenantId";
            var config   = DataAccess.GetList <Models.SysConfig>(sqlwhere, new { name = conf.ToString(), tenantId }).FirstOrDefault();

            if (config == null)
            {
                config = new Models.SysConfig()
                {
                    ConfigCode = conf.ToString(), ConfigName = conf.ToString(), ConfigValue = val, TenantId = tenantId
                };
                DataAccess.AddEntity(config);
            }
            else
            {
                config.ConfigValue = val;
                DataAccess.UpdateEntity(config);
            }
        }
Ejemplo n.º 2
0
        public void Execute(Message message)
        {
            if (message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Private ||
                message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Channel)
            {
                if (MessageQueueManager.AddChatIfNotPresent(message.Chat.Id))
                {
                    Models.SysConfig startMessage = CacheData.SysConfigs
                                                    .SingleOrDefault(x => x.SysConfigId == "StartMessage");
                    if (startMessage == null)
                    {
                        Manager.BotClient.SendTextMessageAsync(
                            chatId: message.Chat.Id,
                            text: $"Your chat {message.Chat.Title} has been added successfully!"
                            );
                        return;
                    }

                    Manager.BotClient.SendTextMessageAsync(
                        chatId: message.Chat.Id,
                        parseMode: Telegram.Bot.Types.Enums.ParseMode.Markdown,
                        text: Utils.Parsers.VariablesParser(startMessage.Value, message)
                        );
                    return;
                }

                Manager.BotClient.SendTextMessageAsync(
                    chatId: message.Chat.Id,
                    text: $"Error adding chat {message.Chat.Title}! Please contact our support"
                    );
                return;
            }

            if (message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Group ||
                message.Chat.Type == Telegram.Bot.Types.Enums.ChatType.Supergroup)
            {
                return;
            }

            Manager.BotClient.SendTextMessageAsync(
                chatId: message.Chat.Id,
                text: $"Error: chat type not recognized. Please contact our support."
                );
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="tenantId"></param>
        /// <returns></returns>
        public static string GetConfig(string name, int tenantId)
        {
            var configKey   = "SystemConfig:Tenant:" + tenantId + ":name:" + name;
            var configValue = CacheHelper.CacheService.Get <string>(configKey);

            if (configValue == null)
            {
                var sql = "select ConfigValue from Sys_Config where TenantId = " + tenantId + " and ConfigName='" + name.ReplaceSql() + "'";
                configValue = DataAccess.ExecuteScalar(sql) as string;
                if (configValue == null)
                {
                    configValue = string.Empty;
                    var config = new Models.SysConfig();
                    config.ConfigCode  = name;
                    config.ConfigName  = name;
                    config.ConfigValue = configValue;
                    config.TenantId    = tenantId;
                    DataAccess.AddEntity(config);
                    CacheHelper.CacheService.Add(configKey, configValue, CachingExpirationType.Stable);
                }
            }
            return(configValue);
        }
Ejemplo n.º 4
0
        public FilterResult DoCheck(Message message, string text)
        {
            Models.Group.ConfigurationParameter configValue = CacheData.GroupConfigs[message.Chat.Id]
                                                              .Where(x => x.ConfigurationParameterId == "ScamFilter")
                                                              .SingleOrDefault();
            if (configValue != null)
            {
                if (configValue.Value == "false")
                {
                    return new FilterResult()
                           {
                               CheckName = "ScamFilter",
                               Result    = IFilter.FilterResultType.skipped
                           }
                }
            }
            ;

            string regex = @"(http:\/\/|ftp:\/\/|https:\/\/)?([\w_-]+\s?(?:(?:\.[a-zA-Z_-]{2,})+))([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-])?";
            // string regex = @"(http:\/\/|ftp:\/\/|https:\/\/)?([a-zA-Z_-]+\s?(?:(?:\.\s?[\w_-]{2,})+)?)\s?\.\s?([\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-]{2,})?";
            Regex           reg          = new Regex(regex, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
            MatchCollection matchedWords = reg.Matches(text);

            if (matchedWords.Count == 0)
            {
                return(new FilterResult()
                {
                    CheckName = "ScamFilter",
                    Result = IFilter.FilterResultType.negative
                });
            }

            if (lastUpdate < DateTime.UtcNow.AddDays(-1))
            {
                updateLinksList();
            }

            if (String.IsNullOrEmpty(linksList))
            {
                return new FilterResult()
                       {
                           CheckName = "ScamFilter",
                           Result    = IFilter.FilterResultType.skipped
                       }
            }
            ;

            foreach (Match match in matchedWords)
            {
                string cleanValue = match.Value.Replace(" ", "");

                // if text does not contain dot and is shorter than 4 chars can't be a link
                if (!cleanValue.Contains(".") && cleanValue.Length < 4)
                {
                    continue;
                }

                if (!safeSingleLetter.Contains(cleanValue))
                {
                    string toCheck = match.Value;
                    if (!match.Value.StartsWith("http://") &&
                        !match.Value.StartsWith("https://"))
                    {
                        toCheck = "://" + match.Value;
                    }
                    else if (match.Value.StartsWith("https"))
                    {
                        toCheck = match.Value.Remove(0, 5);
                    }
                    else if (match.Value.StartsWith("http"))
                    {
                        toCheck = match.Value.Remove(0, 4);
                    }

                    toCheck = toCheck
                              .Replace("/", @"\/")
                              .Replace(".", @"\.")
                              .Replace("?", @"\?");

                    string regexToTest = string.Format(@"{0}[\w.,@?^=%&:\/~+#-]*[\w@?^=%&\/~+#-]?", toCheck);
                    Regex  matchTest   = new Regex(regexToTest, RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
                    if (matchTest.IsMatch(linksList))
                    {
                        return(new FilterResult()
                        {
                            CheckName = "ScamFilter",
                            Result = IFilter.FilterResultType.positive
                        });
                    }
                }
            }

            return(new FilterResult()
            {
                CheckName = "ScamFilter",
                Result = IFilter.FilterResultType.negative
            });
        }

        void updateLinksList()
        {
            safeSingleLetter = new List <string>();
            safeSingleLetter.Add("a.co");
            safeSingleLetter.Add("a.org");
            safeSingleLetter.Add("b.org");
            safeSingleLetter.Add("e.im");
            safeSingleLetter.Add("g.co");
            safeSingleLetter.Add("i.net");
            safeSingleLetter.Add("m.me");
            safeSingleLetter.Add("n.pr");
            safeSingleLetter.Add("o.co");
            safeSingleLetter.Add("q.com");
            safeSingleLetter.Add("q.net");
            safeSingleLetter.Add("s.co");
            safeSingleLetter.Add("s.de");
            safeSingleLetter.Add("t.com");
            //safeSingleLetter.Add("t.me");
            safeSingleLetter.Add("u.ae");
            safeSingleLetter.Add("w.org");
            safeSingleLetter.Add("y.org");
            safeSingleLetter.Add("x.com");
            safeSingleLetter.Add("x.org");
            safeSingleLetter.Add("z.com");

            Models.SysConfig sitesList = CacheData.SysConfigs.Where(x => x.SysConfigId == "PhishingLinks")
                                         .SingleOrDefault();
            if (sitesList == null)
            {
                return;
            }

            using (System.Net.WebClient client = new System.Net.WebClient())
            {
                try
                {
                    linksList = client.DownloadString(sitesList.Value);
                }
                catch (Exception ex)
                {
                    Data.Utils.Logging.AddLog(new Models.SystemLog()
                    {
                        LoggerName = CacheData.LoggerName,
                        Date       = DateTime.Now,
                        Function   = "Terminal.Filters.ScamFilter.updateLinksList",
                        Level      = Models.SystemLog.Levels.Error,
                        Message    = "Error getting updated phishing links!",
                        UserId     = -1
                    });
                    Data.Utils.Logging.AddLog(new Models.SystemLog()
                    {
                        LoggerName = CacheData.LoggerName,
                        Date       = DateTime.Now,
                        Function   = "Terminal.Filters.ScamFilter.updateLinksList",
                        Level      = Models.SystemLog.Levels.Error,
                        Message    = ex.Message,
                        UserId     = -1
                    });
                }
            }
        }
    }