Exemplo n.º 1
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            var controller = context.Controller;

            if (!(controller is IIndexerController))
            {
                return;
            }

            var indexerController = controller as IIndexerController;

            var parameters = context.RouteData.Values;

            if (!parameters.ContainsKey("indexerId"))
            {
                indexerController.CurrentIndexer = null;
                context.Result = ResultsController.GetErrorActionResult(context.RouteData, HttpStatusCode.NotFound, 200, "Indexer is not specified");
                return;
            }

            var indexerId = parameters["indexerId"] as string;

            if (indexerId.IsNullOrEmptyOrWhitespace())
            {
                indexerController.CurrentIndexer = null;
                context.Result = ResultsController.GetErrorActionResult(context.RouteData, HttpStatusCode.NotFound, 201, "Indexer is not specified (empty value)");
                return;
            }

            var indexerService = indexerController.IndexerService;
            var indexer        = indexerService.GetIndexer(indexerId);

            if (indexer == null)
            {
                indexerController.CurrentIndexer = null;
                context.Result = ResultsController.GetErrorActionResult(context.RouteData, HttpStatusCode.NotFound, 201, "Indexer is not supported");
                return;
            }

            if (!indexer.IsConfigured)
            {
                indexerController.CurrentIndexer = null;
                context.Result = ResultsController.GetErrorActionResult(context.RouteData, HttpStatusCode.NotFound, 201, "Indexer is not configured");
                return;
            }

            indexerController.CurrentIndexer = indexer;
        }
Exemplo n.º 2
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            var validApiKey = serverService.GetApiKey();
            var queryParams = context.HttpContext.Request.Query;
            var queryApiKey = queryParams.Where(x => x.Key == "apikey" || x.Key == "passkey").Select(x => x.Value).FirstOrDefault();

#if DEBUG
            if (Debugger.IsAttached)
            {
                return;
            }
#endif
            if (queryApiKey != validApiKey)
            {
                context.Result = ResultsController.GetErrorActionResult(context.RouteData, HttpStatusCode.Unauthorized, 100, "Invalid API Key");
            }
        }
Exemplo n.º 3
0
        public void OnActionExecuting(ActionExecutingContext context)
        {
            //TODO: Not sure what this is meant to do
            //if (context.HttpContext.Response != null)
            //    return;

            var controller = context.Controller;

            if (!(controller is IResultController))
            {
                return;
            }

            var resultController = controller as IResultController;

            var query     = context.ActionArguments.First().Value;
            var queryType = query.GetType();
            var converter = queryType.GetMethod("ToTorznabQuery", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);

            if (converter == null)
            {
                context.Result = ResultsController.GetErrorActionResult(context.RouteData, HttpStatusCode.BadRequest, 900, "ToTorznabQuery() not found");
            }

            var converted    = converter.Invoke(null, new object[] { query });
            var torznabQuery = converted as TorznabQuery;

            resultController.CurrentQuery = torznabQuery;

            if (queryType == typeof(ApiSearch)) // Skip CanHandleQuery() check for manual search (CurrentIndexer isn't used during manul search)
            {
                return;
            }

            if (!resultController.CurrentIndexer.CanHandleQuery(resultController.CurrentQuery))
            {
                context.Result = ResultsController.GetErrorActionResult(context.RouteData, HttpStatusCode.BadRequest, 201, $"{resultController.CurrentIndexer.ID} " +
                                                                        $"does not support the requested query. Please check the capabilities (t=caps) and make sure the search mode and categories are supported.");
            }
        }