diff --git a/Teknik/Areas/Stream/Controllers/StreamController.cs b/Teknik/Areas/Stream/Controllers/StreamController.cs index 3d4882c..5c5342f 100644 --- a/Teknik/Areas/Stream/Controllers/StreamController.cs +++ b/Teknik/Areas/Stream/Controllers/StreamController.cs @@ -24,46 +24,30 @@ namespace Teknik.Areas.Stream.Controllers [AllowAnonymous] public ActionResult ViewStream(int id) { - if (Config.StreamConfig.Enabled) + try { - if (id > 0 && id <= Config.StreamConfig.Sources.Count) + if (Config.StreamConfig.Enabled) { - // ID is valid, so let's get the stream - string source = Config.StreamConfig.Sources[id - 1]; - - System.IO.Stream stream = null; - - //This controls how many bytes to read at a time and send to the client - int bytesToRead = 10000; - - // Buffer to read bytes in chunk size specified above - byte[] buffer = new Byte[bytesToRead]; - - - try + if (id > 0 && id <= Config.StreamConfig.Sources.Count) { + // ID is valid, so let's get the stream + string source = Config.StreamConfig.Sources[id - 1]; //Create a WebRequest to get the file HttpWebRequest fileReq = (HttpWebRequest)HttpWebRequest.Create(source); //Create a response for this request HttpWebResponse fileResp = (HttpWebResponse)fileReq.GetResponse(); - if (fileReq.ContentLength > 0) - fileResp.ContentLength = fileReq.ContentLength; - - //Get the Stream returned from the response - stream = fileResp.GetResponseStream(); - - return File(stream, "image/jpeg"); - } - catch (Exception ex) - { - return Redirect(Url.SubRouteUrl("error", "Error.Http404")); + return File(fileResp.GetResponseStream(), fileResp.ContentType); } + return Redirect(Url.SubRouteUrl("error", "Error.Http404")); } - return Redirect(Url.SubRouteUrl("error", "Error.Http404")); + return Redirect(Url.SubRouteUrl("error", "Error.Http403")); + } + catch (Exception ex) + { + return Redirect(Url.SubRouteUrl("error", "Error.Exception", new { exception = ex })); } - return Redirect(Url.SubRouteUrl("error", "Error.Http403")); } } } \ No newline at end of file diff --git a/Teknik/Areas/Transparency/Views/Transparency/Index.cshtml b/Teknik/Areas/Transparency/Views/Transparency/Index.cshtml index 23cdcdc..caf0482 100644 --- a/Teknik/Areas/Transparency/Views/Transparency/Index.cshtml +++ b/Teknik/Areas/Transparency/Views/Transparency/Index.cshtml @@ -250,6 +250,32 @@ } } +
+

+ -----BEGIN PGP SIGNED MESSAGE-----
+ Hash: SHA1
+
+ Beginning January 1st, 2014 until today, May 12, 2016, Teknik has not recieved a national security letter, FISA order, or any other classified request for user information.
+
+ This notice is valid until June 12, 2016.
+ -----BEGIN PGP SIGNATURE-----
+ Version: GnuPG v1
+
+ iQIcBAEBAgAGBQJXNCtdAAoJEP4EVManSeNwn/MP/04nujsrABZyJyoE0MCP+gk2
+ bKAwhQKsjv2UxP/eK2UD7E6W8B5uuMl9THYYQWZWkTYlGW2QWaeiI2jqwbAU5tWu
+ WpmsmaPGWErTM32cTdcqJQOO3eo8xc8y9KIIDWhrilIkIttDNbmKohvu7nbLgo4Q
+ r1ugDIcqu3J7TEueTik2tGNKuD7UyXH+mv+mkEp+FS7aqR9Ub7k4cDczTrVekoAv
+ Ux+ol9Vm/RCwLGB3orLiPU8jhU2aqMMHy4+s7jnuqTiEGNNyUULXhF0yclIytdQE
+ d2kDyQ1nnBCpuET9Y198e/1jQlxBHX0VCX0h6hE9BKk7s1y1B+WIt1fEgEdVHAn4
+ Cc+bkp4aPmVT4tvSnncP+Lqpj7yBwlbFI/m6W1oQ5m6WL9aVMoreWh/AkU+HmaMc
+ j4Hsjo3PuPOoaa4gcX8dQMSVtATsX1Hnnu3f0YNOZwb2UmYHe+FmaDdGryIp9qTw
+ oVDOV8q5VfjyDDOJ3VbhztOPA3jEoG4bsb2S5eLVCbFrGka1In81W141aq9Lgbv3
+ 5L8gUpiqcv6HEfbwkEU8EzfMryep764PHVvquWIjirKabiPC0TUQoqabndhLQ5Ix
+ onZCq5ObyeQxTrus/xjPogu2yZcboiydrav0J8PXwotvaVDUZmrGXuuqosQwfQ1T
+ HvABK7OR5ZLetP0Co5LR
+ =/G4U
+ -----END PGP SIGNATURE----- +

\ No newline at end of file diff --git a/Teknik/Helpers/ActionResultHelper.cs b/Teknik/Helpers/ActionResultHelper.cs new file mode 100644 index 0000000..7423966 --- /dev/null +++ b/Teknik/Helpers/ActionResultHelper.cs @@ -0,0 +1,87 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Linq; +using System.Net; +using System.Web; +using System.Web.Mvc; + +namespace Teknik.Helpers +{ + /// + /// Result for relaying an HttpWebResponse + /// + public class HttpWebResponseResult : ActionResult + { + private readonly HttpWebResponse _response; + private readonly ActionResult _innerResult; + + /// + /// Relays an HttpWebResponse as verbatim as possible. + /// + /// The HTTP response to relay + public HttpWebResponseResult(HttpWebResponse responseToRelay) + { + if (responseToRelay == null) + { + throw new ArgumentNullException("response"); + } + + _response = responseToRelay; + + Stream contentStream; + if (responseToRelay.ContentEncoding.Contains("gzip")) + { + contentStream = new GZipStream(responseToRelay.GetResponseStream(), CompressionMode.Decompress); + } + else if (responseToRelay.ContentEncoding.Contains("deflate")) + { + contentStream = new DeflateStream(responseToRelay.GetResponseStream(), CompressionMode.Decompress); + } + else + { + contentStream = responseToRelay.GetResponseStream(); + } + + + if (string.IsNullOrEmpty(responseToRelay.CharacterSet)) + { + // File result + _innerResult = new FileStreamResult(contentStream, responseToRelay.ContentType); + } + else + { + // Text result + var contentResult = new ContentResult(); + contentResult = new ContentResult(); + contentResult.Content = new StreamReader(contentStream).ReadToEnd(); + _innerResult = contentResult; + } + } + + public override void ExecuteResult(ControllerContext context) + { + var clientResponse = context.HttpContext.Response; + clientResponse.StatusCode = (int)_response.StatusCode; + + foreach (var headerKey in _response.Headers.AllKeys) + { + switch (headerKey) + { + case "Content-Length": + case "Transfer-Encoding": + case "Content-Encoding": + // Handled by IIS + break; + + default: + clientResponse.AddHeader(headerKey, _response.Headers[headerKey]); + break; + } + } + + _innerResult.ExecuteResult(context); + } + } +} \ No newline at end of file diff --git a/Teknik/Teknik.csproj b/Teknik/Teknik.csproj index 3ac9b8f..0a13582 100644 --- a/Teknik/Teknik.csproj +++ b/Teknik/Teknik.csproj @@ -265,6 +265,7 @@ Global.asax +