public ActionResult Index() { IEnumerable <AllPageCameraDef> cams = TimelapseWrapper.cfg.EnabledCameras .Where(cam => cam.showOnAllPage) .Where(cam => IpWhitelist.IsWhitelisted(Context.httpProcessor.RemoteIPAddressStr, cam.ipWhitelist)) .Select(cam => cam.GetAllPageCameraDef()); return(Json(cams)); }
public ActionResult Index(params string[] args) { if (args.Length == 0) { return(Error("Bad Request", "400 Bad Request")); } CameraSpec cs = TimelapseWrapper.cfg.GetCameraSpec(args[0]); if (cs == null || !cs.enabled) { return(Error("Camera Not Found", "404 Not Found")); } if (!IpWhitelist.IsWhitelisted(Context.httpProcessor.RemoteIPAddressStr, cs.ipWhitelist)) { return(Error("Forbidden", "403 Forbidden")); } string latestImagePathPart; try { latestImagePathPart = Navigation.GetLatestImagePath(cs, out string latestImgTime, out DateTime dateTime); } catch (NavigationException) { return(Error("Service Unavailable", "503 Service Unavailable")); } string path = cs.id + "/" + latestImagePathPart; if (path == Context.httpProcessor.GetHeaderValue("if-none-match")) { return new StatusCodeResult("304 Not Modified") { ContentType = "image/jpeg" } } ; byte[] data = WebServerUtil.GetImageData(path); JpegImageResult result = new JpegImageResult(data); List <KeyValuePair <string, string> > headers = WebServerUtil.GetCacheEtagHeaders(TimeSpan.Zero, path); FileInfo imgFile = new FileInfo(TimelapseGlobals.ImageArchiveDirectoryBase + path); headers.Add(new KeyValuePair <string, string>("Content-Disposition", "inline; filename=\"" + cs.name + " " + imgFile.Name.Substring(0, imgFile.Name.Length - imgFile.Extension.Length) + ".jpg\"")); headers.ForEach(h => result.AddOrUpdateHeader(h.Key, h.Value)); return(result); }
private void OnAccept(IAsyncResult result) { TcpClient tcpClient; try { tcpClient = _listener.EndAcceptTcpClient(result); } catch (ObjectDisposedException) { LogDebug("Socket was closed"); return; } var ip = ((IPEndPoint)tcpClient.Client.RemoteEndPoint).Address; if (MaxConnections > 0) { if (_clients.Count >= MaxConnections) { LogDebug("Rejected new connection from " + ip + " (Server full.)"); tcpClient.Close(); return; } } if (MaxConnectionsPerIp > 0) { var count = 0; foreach (var tcpClient1 in _clients) { if (((IPEndPoint)tcpClient1.Client.RemoteEndPoint).Address.ToString() == ip.ToString()) { count++; } } if (count >= MaxConnectionsPerIp) { LogDebug("Rejected new connection from " + ip + " (Too many connections from this IP)"); tcpClient.Close(); return; } } if (EnableIpWhitelist) { if (!IpWhitelist.Any(p => IpExtension.Match(p, ip.ToString()))) { LogDebug("Rejected new connection from " + ip + " (Not in whitelist)"); tcpClient.Close(); return; } } if (IpBanList.ContainsKey(ip.ToString())) { if (IpBanList[ip.ToString()] - DateTime.Now.ToUnixTimestamp() > 0) { LogDebug("Rejected new connection from " + ip + " (Banned till " + DateTimeExtensions.FromUnixTimestamp(IpBanList[ip.ToString()]).ToString("F") + ")"); tcpClient.Close(); return; } IpBanList.Remove(ip.ToString()); } LogDebug("Accepted new connection from " + ip); new RemoteConTcpClient(tcpClient, this); _clients.Add(tcpClient); if (!_listener.Server.IsBound) { return; } _listener.BeginAcceptTcpClient(OnAccept, _listener); }