public SpiderMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider routeProvider,
                                IRouteDataService routeDataService, IPluginHelperService pluginHelperService,
                                IPluginTypesService pluginTypesService, ISettingsProvider settingsProvider)
        {
            if (routeProvider == null)
            {
                throw new ArgumentNullException(nameof(routeProvider));
            }

            if (routeDataService == null)
            {
                throw new ArgumentNullException(nameof(routeDataService));
            }

            if (pluginHelperService == null)
            {
                throw new ArgumentNullException(nameof(pluginHelperService));
            }

            _next = next;

            _userSessionManagerLoaded = pluginHelperService.PluginLoaded("UserSessionMiddleware.Plugin.dll", out int version);

            _deniedSpiderRoutes = new List <DeniedRoute>();
            LoadSpiderData(routeProvider, routeDataService, pluginTypesService);

            SpiderSettings settings = settingsProvider.GetSettings <SpiderSettings>("Spider.Plugin");

            _processStaticFiles = settings.ProcessStaticFiles;

            if (!String.IsNullOrEmpty(settings.StaticFileExtensions))
            {
                _staticFileExtensions = settings.StaticFileExtensions;
            }
        }
Exemplo n.º 2
0
        public BreadcrumbMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider routeProvider,
                                    IRouteDataService routeDataService, IPluginHelperService pluginHelperService,
                                    IPluginTypesService pluginTypesService, ISettingsProvider settingsProvider,
                                    IPluginClassesService pluginClassesService, ILogger logger)
        {
            if (routeProvider == null)
            {
                throw new ArgumentNullException(nameof(routeProvider));
            }

            if (routeDataService == null)
            {
                throw new ArgumentNullException(nameof(routeDataService));
            }

            if (pluginHelperService == null)
            {
                throw new ArgumentNullException(nameof(pluginHelperService));
            }

            if (pluginClassesService == null)
            {
                throw new ArgumentNullException(nameof(pluginClassesService));
            }

            if (pluginTypesService == null)
            {
                throw new ArgumentNullException(nameof(pluginTypesService));
            }

            if (settingsProvider == null)
            {
                throw new ArgumentNullException(nameof(settingsProvider));
            }

            _next   = next;
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));

            if (pluginHelperService.PluginLoaded(Constants.PluginNameLocalization, out int _))
            {
                List <IStringLocalizer> stringLocalizers = pluginClassesService.GetPluginClasses <IStringLocalizer>();

                if (stringLocalizers.Count > 0)
                {
                    _stringLocalizer = stringLocalizers[0];
                }
            }

            BreadcrumbSettings settings = settingsProvider.GetSettings <BreadcrumbSettings>(Constants.PluginSettingBreadcrumb);

            _homeBreadCrumb = new BreadcrumbItem(settings.HomeName,
                                                 $"{Constants.ForwardSlash}{settings.HomeController}{Constants.ForwardSlash}{settings.DefaultAction}", false);

            LoadBreadcrumbData(routeProvider, routeDataService, pluginTypesService, settings);

            if (!String.IsNullOrEmpty(settings.StaticFileExtensions))
            {
                _staticFileExtensions = settings.StaticFileExtensions;
            }
        }
Exemplo n.º 3
0
        public RestrictIpMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider routeProvider,
                                    IRouteDataService routeDataService, IPluginHelperService pluginHelperService,
                                    IPluginTypesService pluginTypesService, ISettingsProvider settingsProvider, ILogger logger)
        {
            if (routeProvider == null)
            {
                throw new ArgumentNullException(nameof(routeProvider));
            }

            if (routeDataService == null)
            {
                throw new ArgumentNullException(nameof(routeDataService));
            }

            if (pluginHelperService == null)
            {
                throw new ArgumentNullException(nameof(pluginHelperService));
            }

            _next             = next;
            _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
            _localIpAddresses = new HashSet <string>();
            _restrictedRoutes = new Dictionary <string, List <string> >();
            GetLocalIpAddresses(_localIpAddresses);
            RestrictIpSettings settings = settingsProvider.GetSettings <RestrictIpSettings>("RestrictedIpRoutes.Plugin");

            _disabled = settings.Disabled;

            if (_disabled)
            {
                _logger.AddToLog(LogLevel.Information, RestrictedIpDisabled);
            }

            LoadRestrictedIpRouteData(routeProvider, routeDataService, pluginTypesService, settings);
        }
 public SkillionRouteValueTransformer(
     ISkillRequestParser skillRequestParser,
     IRouteDataService routeDataService,
     ILogger <SkillionRouteValueTransformer> logger = null)
 {
     _skillRequestParser = skillRequestParser;
     _routeDataService   = routeDataService;
     _logger             = logger;
 }
        public UserSessionMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider routeProvider,
                                     IRouteDataService routeDataService, IPluginTypesService pluginTypesService, ISettingsProvider settingsProvider)
        {
            if (routeProvider == null)
            {
                throw new ArgumentNullException(nameof(routeProvider));
            }

            if (routeDataService == null)
            {
                throw new ArgumentNullException(nameof(routeDataService));
            }

            if (pluginTypesService == null)
            {
                throw new ArgumentNullException(nameof(pluginTypesService));
            }

            if (settingsProvider == null)
            {
                throw new ArgumentNullException(nameof(settingsProvider));
            }

            _next = next;

            _routeData = new List <RouteData>();

            UserSessionSettings Settings = settingsProvider.GetSettings <UserSessionSettings>(Constants.UserSessionConfiguration);

            Settings.SessionTimeout = Shared.Utilities.CheckMinMax(Settings.SessionTimeout, 15, 200);

            UserSessionManager.InitialiseSessionManager(new TimeSpan(0, (int)Settings.SessionTimeout, 0));

            SessionHelper.InitSessionHelper();

            if (!String.IsNullOrWhiteSpace(Settings.CookieName))
            {
                _cookieName = Settings.CookieName;
            }

            if (!String.IsNullOrWhiteSpace(Settings.EncryptionKey))
            {
                _cookieEncryptionKey = Settings.EncryptionKey;
            }

            if (!String.IsNullOrWhiteSpace(Settings.StaticFileExtensions))
            {
                _staticFileExtension = Settings.StaticFileExtensions;
            }

            _defaultCulture = Settings.DefaultCulture;

            LoadLoggedInOutData(routeProvider, routeDataService, pluginTypesService);
            LoadLoggedInData(routeProvider, routeDataService, pluginTypesService);
            LoadLoggedOutData(routeProvider, routeDataService, pluginTypesService);
        }
        public BadEggMiddleware(RequestDelegate next, IActionDescriptorCollectionProvider routeProvider,
                                IRouteDataService routeDataService, IPluginHelperService pluginHelperService,
                                IPluginTypesService pluginTypesService, IIpValidation ipValidation,
                                ISettingsProvider settingsProvider, INotificationService notificationService)
        {
            if (routeProvider == null)
            {
                throw new ArgumentNullException(nameof(routeProvider));
            }

            if (routeDataService == null)
            {
                throw new ArgumentNullException(nameof(routeDataService));
            }

            if (pluginHelperService == null)
            {
                throw new ArgumentNullException(nameof(pluginHelperService));
            }

            if (pluginTypesService == null)
            {
                throw new ArgumentNullException(nameof(pluginTypesService));
            }

            if (settingsProvider == null)
            {
                throw new ArgumentNullException(nameof(settingsProvider));
            }

            _next = next;

            _userSessionManagerLoaded = pluginHelperService.PluginLoaded(Constants.PluginNameUserSession, out int version);
            _ipValidation             = ipValidation ?? throw new ArgumentNullException(nameof(ipValidation));
            _notificationService      = notificationService ?? throw new ArgumentNullException(nameof(notificationService));

            _managedRoutes = new List <ManagedRoute>();
            LoadRouteData(routeProvider, routeDataService, pluginTypesService);

            _badEggSettings = settingsProvider.GetSettings <BadEggSettings>("BadEgg.Plugin");

            _validateConnections = new ValidateConnections(
                _badEggSettings.ConnectionTimeOut,
                _badEggSettings.ConnectionsPerMinute);
            _validateConnections.ConnectionAdd      += ValidateConnections_ConnectionAdd;
            _validateConnections.ConnectionRemove   += ValidateConnections_ConnectionRemove;
            _validateConnections.OnReportConnection += ValidateConnections_OnReportConnection;
            _validateConnections.OnBanIPAddress     += ValidateConnections_OnBanIPAddress;

            ThreadManager.ThreadStart(_validateConnections, "Bad Egg Validation", ThreadPriority.Lowest);
        }
        private void LoadRouteData(IActionDescriptorCollectionProvider routeProvider,
                                   IRouteDataService routeDataService, IPluginTypesService pluginTypesService)
        {
            List <Type> badeggAttributes = pluginTypesService.GetPluginTypesWithAttribute <BadEggAttribute>();

            if (badeggAttributes.Count > 0)
            {
                // Cycle through all classes and methods which have the bad egg attribute
                foreach (Type type in badeggAttributes)
                {
                    // is it a class attribute
                    BadEggAttribute attribute = (BadEggAttribute)type.GetCustomAttributes(true)
                                                .Where(a => a.GetType() == typeof(BadEggAttribute)).FirstOrDefault();

                    if (attribute != null)
                    {
                        string route = routeDataService.GetRouteFromClass(type, routeProvider);

                        if (String.IsNullOrEmpty(route))
                        {
                            continue;
                        }

                        _managedRoutes.Add(new ManagedRoute($"{route.ToLower()}", attribute.ValidateQueryFields, attribute.ValidateFormFields));
                    }

                    // look for specific method disallows

                    foreach (MethodInfo method in type.GetMethods())
                    {
                        attribute = (BadEggAttribute)method.GetCustomAttributes(true)
                                    .Where(a => a.GetType() == typeof(BadEggAttribute)).FirstOrDefault();

                        if (attribute != null)
                        {
                            string route = routeDataService.GetRouteFromMethod(method, routeProvider);

                            if (String.IsNullOrEmpty(route))
                            {
                                continue;
                            }


                            _managedRoutes.Add(new ManagedRoute($"{route.ToLower()}", attribute.ValidateQueryFields, attribute.ValidateFormFields));
                        }
                    }
                }
            }
        }
        private void LoadSpiderData(IActionDescriptorCollectionProvider routeProvider,
                                    IRouteDataService routeDataService, IPluginTypesService pluginTypesService)
        {
            string      spiderTextFile   = String.Empty;
            List <Type> spiderAttributes = pluginTypesService.GetPluginTypesWithAttribute <DenySpiderAttribute>();

            if (spiderAttributes.Count == 0)
            {
                spiderTextFile = "# Allow all from Spider.Plugin\r\n\r\nUser-agent: *";
            }
            else
            {
                // Cycle through all classes and methods which have the spider attribute
                foreach (Type type in spiderAttributes)
                {
                    // is it a class attribute
                    DenySpiderAttribute attribute = (DenySpiderAttribute)type.GetCustomAttributes(true)
                                                    .Where(a => a.GetType() == typeof(DenySpiderAttribute)).FirstOrDefault();

                    if (attribute != null)
                    {
                        string route = routeDataService.GetRouteFromClass(type, routeProvider);

                        if (String.IsNullOrEmpty(route))
                        {
                            continue;
                        }

                        if (!String.IsNullOrEmpty(attribute.Comment))
                        {
                            spiderTextFile += $"# {attribute.Comment}\r\n\r\n";
                        }

                        spiderTextFile += $"User-agent: {attribute.UserAgent}\r\n";
                        spiderTextFile += $"Disallow: /{route}/\r\n\r\n";

                        _deniedSpiderRoutes.Add(new DeniedRoute($"/{route.ToLower()}/", attribute.UserAgent));
                    }

                    // look for specific method disallows

                    foreach (MethodInfo method in type.GetMethods())
                    {
                        attribute = (DenySpiderAttribute)method.GetCustomAttributes(true)
                                    .Where(a => a.GetType() == typeof(DenySpiderAttribute)).FirstOrDefault();

                        if (attribute != null)
                        {
                            string route = routeDataService.GetRouteFromMethod(method, routeProvider);

                            if (String.IsNullOrEmpty(route))
                            {
                                continue;
                            }

                            if (!String.IsNullOrEmpty(attribute.Comment))
                            {
                                spiderTextFile += $"# {attribute.Comment}\r\n\r\n";
                            }

                            spiderTextFile += $"User-agent: {attribute.UserAgent}\r\n";
                            spiderTextFile += $"Disallow: {route}\r\n\r\n";

                            _deniedSpiderRoutes.Add(new DeniedRoute($"{route.ToLower()}", attribute.UserAgent));
                        }
                    }
                }
            }

            _spiderData = Encoding.UTF8.GetBytes(spiderTextFile);
        }