public override void OnActionExecuting(HttpActionContext actionContext) { var controller = actionContext.ControllerContext.Controller; if (!(controller is IIndexerController)) { return; } var indexerController = controller as IIndexerController; var parameters = actionContext.RequestContext.RouteData.Values; if (!parameters.ContainsKey("indexerId")) { indexerController.CurrentIndexer = null; actionContext.Response = ResultsController.GetErrorHttpResponseMessage(actionContext, HttpStatusCode.NotFound, 200, $"indexer is not specified"); return; } var indexerId = parameters["indexerId"] as string; if (indexerId.IsNullOrEmptyOrWhitespace()) { indexerController.CurrentIndexer = null; actionContext.Response = ResultsController.GetErrorHttpResponseMessage(actionContext, 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; actionContext.Response = ResultsController.GetErrorHttpResponseMessage(actionContext, HttpStatusCode.NotFound, 201, $"Indexer is not supported"); return; } if (!indexer.IsConfigured) { indexerController.CurrentIndexer = null; actionContext.Response = ResultsController.GetErrorHttpResponseMessage(actionContext, HttpStatusCode.NotFound, 201, $"Indexer is not configured"); return; } indexerController.CurrentIndexer = indexer; }
public override void OnAuthorization(HttpActionContext actionContext) { var validApiKey = Engine.ServerConfig.APIKey; var queryParams = actionContext.Request.GetQueryNameValuePairs(); 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) { actionContext.Response = ResultsController.GetErrorHttpResponseMessage(actionContext, HttpStatusCode.Unauthorized, 100, $"Invalid API Key"); } }
public override void OnActionExecuting(HttpActionContext actionContext) { base.OnActionExecuting(actionContext); if (actionContext.Response != null) { return; } var controller = actionContext.ControllerContext.Controller; if (!(controller is IResultController)) { return; } var resultController = controller as IResultController; var query = actionContext.ActionArguments.First().Value; var queryType = query.GetType(); var converter = queryType.GetMethod("ToTorznabQuery", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public); if (converter == null) { actionContext.Response = ResultsController.GetErrorHttpResponseMessage(actionContext, 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)) { actionContext.Response = ResultsController.GetErrorHttpResponseMessage(actionContext, HttpStatusCode.NotImplemented, 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."); } }