public ForbiddenResponse Get(string newForbidden) { try { checkPathExistence(path); // Read a text file line by line. string[] lines = System.IO.File.ReadAllLines(path); foreach (string line in lines) { data = data + line; } } catch (Exception ex) { Console.WriteLine("\nException Caught In Domain!"); Console.WriteLine("Message :{0} ", ex.Message); } // Console.WriteLine(data.Domains) FilterJSON deserializedProduct = JsonConvert.DeserializeObject <FilterJSON>(data); // Check if the entry already exists with a set list of domains foreach (var entry in deserializedProduct.Domains) { if (entry == newForbidden) { return(new ForbiddenResponse { StatusCode = "304", ResponseMessage = "Not Modified", HydratedContent = deserializedProduct }); } } // Adds new forbidden domain to a list of domains deserializedProduct.Domains.Add(newForbidden); // 1. Overwrite the current files // 2. Dumps to the file again the new contents System.IO.File.WriteAllText(path, JsonConvert.SerializeObject(deserializedProduct)); // Return a new response return(new ForbiddenResponse { StatusCode = "200", ResponseMessage = "OK", HydratedContent = deserializedProduct }); }
public async Task <server.Request> Domain(string domain, Int32 clientId, Int32 requestId) { try { checkPathExistence(path); // Read a text file line by line. string[] lines = System.IO.File.ReadAllLines(path); foreach (string line in lines) { data = data + line; } } catch (Exception ex) { Console.WriteLine("\nException Caught In Domain!"); Console.WriteLine("Message :{0} ", ex.Message); } FilterJSON deserializedProduct = JsonConvert.DeserializeObject <FilterJSON>(data); foreach (string name in deserializedProduct.Domains) { if ($"http://www.{name}" == domain || $"www.{name}" == domain || $"{name}" == domain) { server.Request response = new server.Request() { Domain = name, Content = "Forbidden Yaar!\nAdministrator se baat kerni paregi", Title = name, ClientId = clientId, RequestId = requestId, StatusCode = 404, isFromCache = false, }; return(response); } } domain = ConvertToUTF8Standard(domain); // Make HTTP request, yay! Finally return(await HttpInvokeGetAsync(domain, clientId, requestId)); }
public ForbiddenResponse Get(string domainToRemove) { try { checkPathExistence(path); // Read a text file line by line. string[] lines = System.IO.File.ReadAllLines(path); foreach (string line in lines) { data = data + line; } } catch (Exception ex) { Console.WriteLine("\nException Caught In Domain!"); Console.WriteLine("Message :{0} ", ex.Message); } FilterJSON deserializedProduct = JsonConvert.DeserializeObject <FilterJSON>(data); // Check if the entry already exists with a set list of domains foreach (var entry in deserializedProduct.Domains) { if (entry == domainToRemove) { // Remove the found domain deserializedProduct.Domains.Remove(domainToRemove); // 1. Overwrite the current files // 2. Dumps to the file again the new contents System.IO.File.WriteAllText(path, JsonConvert.SerializeObject(deserializedProduct)); return(new ForbiddenResponse { StatusCode = "200", ResponseMessage = "OK", HydratedContent = deserializedProduct }); } } // If no such domain was even found return(new ForbiddenResponse { StatusCode = "400", ResponseMessage = "BAD REQUEST", HydratedContent = deserializedProduct }); }
public async Task <string> Domain(string domain = "", Int32 clientId = -1, Int32 requestId = -1) { if (clientId == -1 || requestId == -1 || domain == "") { return("Parameters not given!"); } try { checkPathExistence(path); // Read a text file line by line. string[] lines = System.IO.File.ReadAllLines(path); foreach (string line in lines) { data = data + line; } } catch (Exception ex) { Console.WriteLine("\nException Caught In Domain!"); Console.WriteLine("Message :{0} ", ex.Message); } FilterJSON deserializedProduct = JsonConvert.DeserializeObject <FilterJSON>(data); foreach (string name in deserializedProduct.Domains) { if ($"http://www.{name}" == domain || $"www.{name}" == domain || $"{name}" == domain) { // return Redirect("http://localhost:3000/forbidden"); RedirectToAction("ForbiddenRequest", "Content"); } } domain = ConvertToUTF8Standard(domain); // Make HTTP request, yay! Finally return(await HttpInvokeGetAsync(domain, clientId, requestId)); }
public FilterJSON Get() { try { checkPathExistence(path); // Read a text file line by line. string[] lines = System.IO.File.ReadAllLines(path); foreach (string line in lines) { data = data + line; } } catch (Exception ex) { Console.WriteLine("\nException Caught In Domain!"); Console.WriteLine("Message :{0} ", ex.Message); } // Console.WriteLine(data.Domains) FilterJSON deserializedProduct = JsonConvert.DeserializeObject <FilterJSON>(data); return(deserializedProduct); }