Exemple #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // Load all active sessions
            LoginSessionRepository loginRepository = new LoginSessionRepository();
            string              userSessionID      = Settings.getSessionIDFromCookies(Settings.logonCookieName, Request);
            LoginSession        currentUser        = loginRepository.Get(userSessionID, Request.ServerVariables["REMOTE_ADDR"], Request.ServerVariables["HTTP_USER_AGENT"]);
            List <LoginSession> AllSessions        = loginRepository.GetActive();

            if (!string.IsNullOrEmpty(Request.QueryString["expiresession"]))
            {
                string hashToExpire = Sanitizers.SanitizeSearchString(Request.QueryString["expiresession"]);
                if (!string.IsNullOrEmpty(hashToExpire))
                {
                    loginRepository.Delete(hashToExpire);
                }
            }

            // Some of the following code won't work if the currentUser object is null. Ideally this shouldn't
            // happen because the template should catch this before this page loads, but it's better to be safe
            if (currentUser != null)
            {
                // Display them in a table
                List <LoginSession> AllSessionsSorted = AllSessions.OrderBy(c => c.Username).ToList <LoginSession>();

                foreach (LoginSession session in AllSessionsSorted)
                {
                    // Determine if this session is the current user
                    bool isCurrentUser = currentUser.Thumbprint == session.Thumbprint;

                    tsblSessions.Rows.Add(AddTableRow_Sessions(session, isCurrentUser, true));
                }
            }
        }
        protected void btnNewCategory_Click(object sender, EventArgs e)
        {
            // Parse the new category
            string CatName = Sanitizers.SanitizeGeneralInputString(txtNewCategoryName.Text);
            string Parent  = Sanitizers.SanitizeGeneralInputString(drpParent.SelectedValue);

            bool Hidden = chkHidden.Checked;

            bool Private = chkPrivate.Checked;

            if ((!string.IsNullOrEmpty(CatName)) && (CatName.Length > 2))
            {
                VideoCategory NewCategory = new VideoCategory()
                {
                    Name             = CatName,
                    ParentCategoryID = Parent,
                    IsHidden         = Hidden,
                    IsPrivate        = Private
                };

                VideoCategoryRepository videoCategoryRepository = new VideoCategoryRepository();
                videoCategoryRepository.Insert(NewCategory);

                txtNewCategoryName.Text = "";
                chkHidden.Checked       = false;
                chkPrivate.Checked      = false;
                refreshCategoryList();
            }
        }
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            // Sanitize input string
            string SanitizedInputString = Sanitizers.SanitizeSearchString(txtSearchTerms.Text);

            // Determine if the viewer is viewing from inside the network
            string clientIP = Request.ServerVariables["REMOTE_ADDR"];
            bool   canUserAccessPrivateContent = Config.CanAccessPrivate(clientIP);

            VideoRepository videoRepository = new VideoRepository();
            List <Video>    foundVideos     = videoRepository.Find(SanitizedInputString, canUserAccessPrivateContent);

            searchResultsTitle.Visible = true;
            litSearchResults.Visible   = true;
            if (foundVideos.Count > 0)
            {
                litSearchResults.Text = "";
                foreach (Video video in foundVideos)
                {
                    litSearchResults.Text += videoListItem(video);
                }
            }
            else
            {
                litSearchResults.Text = "No videos found matching the term '" + SanitizedInputString + "'";
            }

            litCategories.Visible = false;
            litVideos.Visible     = false;
        }
        public void StopRecording(string sessionId, IDictionary <string, string> variables = null, bool saveRecording = true)
        {
            if (!RecordingSessions.TryRemove(sessionId, out var recordingSession))
            {
                return;
            }

            foreach (RecordedTestSanitizer sanitizer in Sanitizers.Concat(recordingSession.AdditionalSanitizers))
            {
                recordingSession.Session.Sanitize(sanitizer);
            }

            if (variables != null)
            {
                foreach (var kvp in variables)
                {
                    recordingSession.Session.Variables[kvp.Key] = kvp.Value;
                }
            }

            if (saveRecording)
            {
                if (String.IsNullOrEmpty(recordingSession.Path))
                {
                    if (!InMemorySessions.TryAdd(sessionId, recordingSession))
                    {
                        throw new HttpException(HttpStatusCode.InternalServerError, $"Unexpectedly failed to add new in-memory session under id {sessionId}.");
                    }
                }
                else
                {
                    var targetPath = GetRecordingPath(recordingSession.Path);

                    // Create directories above file if they don't already exist
                    var directory = Path.GetDirectoryName(targetPath);
                    if (!String.IsNullOrEmpty(directory))
                    {
                        Directory.CreateDirectory(directory);
                    }

                    using var stream = System.IO.File.Create(targetPath);
                    var options = new JsonWriterOptions {
                        Indented = true
                    };
                    var writer = new Utf8JsonWriter(stream, options);
                    recordingSession.Session.Serialize(writer);
                    writer.Flush();
                    stream.Write(Encoding.UTF8.GetBytes(Environment.NewLine));
                }
            }
        }
Exemple #5
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["i"]))
            {
                // Sanitize the video ID
                string requestedID = Sanitizers.SanitizeQueryStringID(Request.QueryString["i"]);

                VideoRepository videoRepository = new VideoRepository();
                Video           video           = videoRepository.Get(requestedID);

                if (video != null)
                {
                    // Determine if the viewer is viewing from inside the network
                    string clientIP = Request.ServerVariables["REMOTE_ADDR"];
                    bool   canUserAccessPrivateContent = Config.CanAccessPrivate(clientIP);

                    if (
                        (video.IsPrivate && canUserAccessPrivateContent) ||
                        (!video.IsPrivate)
                        )
                    {
                        // Set the page title
                        string originalTitle = Page.Header.Title;
                        Page.Header.Title = video.Name + " - " + originalTitle;

                        // Determine which player to display the video in
                        if (video.IsYoutubeAvailable)
                        {
                            litPlayer.Text = YoutubeVideoPlayer.GetHTML(video);
                        }
                        else
                        {
                            litPlayer.Text = HTML5VideoPlayer.GetHTML(video);
                        }
                        tblContainer.Visible = true;

                        litVideoInfo.Text = videoInfoSection(video);
                    }
                    else
                    {
                        displayError("This video is marked as private. you can only watch from within the LSKYSD network.");
                    }
                }
                else
                {
                    displayError("A video with that ID was not found.");
                }
            }
        }
Exemple #6
0
        public override void Populate(Queue <string> parameters)
        {
            if (parameters.Count == 0)
            {
                return;
            }
            Sanitizations = Sanitizers.None;

            while (parameters.Count > 0)
            {
                string parameter = parameters.Dequeue();
                switch (parameter)
                {
                case "-deob": Sanitizations |= Sanitizers.Deobfuscate; break;

                case "-rr": Sanitizations |= Sanitizers.RegisterRename; break;

                case "-ir": Sanitizations |= Sanitizers.IdentifierRename; break;
                }
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            // If the user hasn't selected a category, display a list of categories
            // If the user has selected a category, display all videos in that category

            // Always list categories
            VideoCategoryRepository videoCategoryRepo = new VideoCategoryRepository();
            List <VideoCategory>    VideoCategories   = videoCategoryRepo.GetTopLevel();


            litCategories.Text = addMenuChildren(VideoCategories);

            // If given a category ID, display all videos from that category
            if (!string.IsNullOrEmpty(Request.QueryString["category"]))
            {
                string parsedCatID = Sanitizers.SanitizeGeneralInputString(Request.QueryString["category"].ToString().Trim());

                if (!string.IsNullOrEmpty(parsedCatID))
                {
                    VideoCategory selectedCategory = videoCategoryRepo.Get(parsedCatID);
                    if (selectedCategory != null)
                    {
                        // Determine if the viewer is viewing from inside the network
                        string clientIP = Request.ServerVariables["REMOTE_ADDR"];
                        bool   canUserAccessPrivateContent = Config.CanAccessPrivate(clientIP);


                        VideoRepository videoRepository = new VideoRepository();
                        List <Video>    CategoryVideos  = videoRepository.GetFromCategory(selectedCategory, canUserAccessPrivateContent);

                        StringBuilder VideoListHTML = new StringBuilder();
                        foreach (Video video in CategoryVideos)
                        {
                            VideoListHTML.Append(videoListItem(video));
                        }
                        litVideos.Text = VideoListHTML.ToString();
                    }
                }
            }
        }
        public async Task HandlePlaybackRequest(string recordingId, HttpRequest incomingRequest, HttpResponse outgoingResponse)
        {
            await DebugLogger.LogRequestDetailsAsync(incomingRequest);

            if (!PlaybackSessions.TryGetValue(recordingId, out var session))
            {
                throw new HttpException(HttpStatusCode.BadRequest, $"There is no active playback session under recording id {recordingId}.");
            }

            var entry = await CreateEntryAsync(incomingRequest).ConfigureAwait(false);

            // If request contains "x-recording-remove: false", then request is not removed from session after playback.
            // Used by perf tests to play back the same request multiple times.
            var remove = true;

            if (incomingRequest.Headers.TryGetValue("x-recording-remove", out var removeHeader))
            {
                remove = bool.Parse(removeHeader);
            }

            var match = session.Session.Lookup(entry, session.CustomMatcher ?? Matcher, session.AdditionalSanitizers.Count > 0 ? Sanitizers.Concat(session.AdditionalSanitizers) : Sanitizers, remove);

            foreach (ResponseTransform transform in Transforms.Concat(session.AdditionalTransforms))
            {
                transform.Transform(incomingRequest, match);
            }

            Interlocked.Increment(ref Startup.RequestsPlayedBack);

            outgoingResponse.StatusCode = match.StatusCode;

            foreach (var header in match.Response.Headers)
            {
                outgoingResponse.Headers.Add(header.Key, header.Value.ToArray());
            }

            outgoingResponse.Headers.Remove("Transfer-Encoding");

            if (match.Response.Body?.Length > 0)
            {
                var bodyData = CompressBody(match.Response.Body, match.Response.Headers);

                outgoingResponse.ContentLength = bodyData.Length;

                await outgoingResponse.Body.WriteAsync(bodyData).ConfigureAwait(false);
            }
        }
        /// <summary>
        /// Parses a stream from the input fields on the page
        /// </summary>
        /// <returns></returns>
        private LiveBroadcast ParseStream()
        {
            string ID          = Sanitizers.SanitizeGeneralInputString(lblID.Text);
            string name        = Sanitizers.SanitizeGeneralInputString(txtTitle.Text);
            string location    = Sanitizers.SanitizeGeneralInputString(txtStreamLocation.Text);
            string description = Sanitizers.SanitizeGeneralInputString(txtDescription.Text);
            string thumbnail   = Sanitizers.SanitizeGeneralInputString(drpThumbnail.SelectedValue);
            int    width       = Parsers.ParseInt(txtWidth.Text);
            int    height      = Parsers.ParseInt(txtHeight.Text);
            string YouTubeID   = Sanitizers.SanitizeGeneralInputString(txtYouTubeID.Text);

            DateTime?startDate = Parsers.ParseDateFromUser(drpStartYear.SelectedValue, drpStartMonth.SelectedValue, txtStartDay.Text, txtStartHour.Text, txtStartMinute.Text, "00");
            DateTime?endDate   = Parsers.ParseDateFromUser(drpEndYear.SelectedValue, drpEndMonth.SelectedValue, txtEndDay.Text, txtEndHour.Text, txtEndMinute.Text, "00");

            bool ishidden    = chkHidden.Checked;
            bool isprivate   = chkPrivate.Checked;
            bool forceonline = chkForce.Checked;
            bool isDelayed   = chkDelayed.Checked;
            bool isCancelled = chkCancelled.Checked;
            bool embed       = chkEmbed.Checked;

            // Validate
            if (string.IsNullOrEmpty(name))
            {
                throw new Exception("Name cannot be empty. ");
            }
            if (width <= 0)
            {
                throw new Exception("Width must be more than zero.");
            }
            if (height <= 0)
            {
                throw new Exception("Height must be more than zero.");
            }
            if (startDate == null)
            {
                throw new Exception("Start time cannot be null.");
            }
            if (endDate == null)
            {
                throw new Exception("End time cannot be null.");
            }

            // Return
            return(new LiveBroadcast()
            {
                ID = ID,
                Name = name,
                Location = location,
                Description = description,
                ThumbnailURL = thumbnail,
                Width = width,
                Height = height,
                YouTubeID = YouTubeID,
                StartTime = startDate.Value,
                EndTime = endDate.Value,
                ForcedLive = forceonline,
                IsPrivate = isprivate,
                IsHidden = ishidden,
                IsDelayed = isDelayed,
                IsCancelled = isCancelled,
                EmbedInsteadOfLink = embed
            });
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["i"]))
            {
                // Sanitize the video ID
                string requestedID = Sanitizers.SanitizeQueryStringID(Request.QueryString["i"]);

                // See if this video exists
                LiveBroadcastRepository liveBroadcastRepository = new LiveBroadcastRepository();
                LiveBroadcast           liveStream = liveBroadcastRepository.Get(requestedID);

                if (liveStream != null)
                {
                    // Determine if the viewer is viewing from inside the network
                    string clientIP = Request.ServerVariables["REMOTE_ADDR"];
                    bool   canUserAccessPrivateContent = Config.CanAccessPrivate(clientIP);

                    // Set the page title
                    string originalTitle = Page.Header.Title;
                    Page.Header.Title = liveStream.Name + " - " + originalTitle;

                    if (liveStream.IsEnded && !liveStream.ForcedLive)
                    {
                        displayError("This live stream has ended.");
                    }
                    else
                    {
                        if (
                            ((liveStream.IsPrivate) && (canUserAccessPrivateContent)) ||
                            (!liveStream.IsPrivate))
                        {
                            tblContainer.Visible = true;
                            if (liveStream.EmbedInsteadOfLink)
                            {
                                litPlayer.Text = YoutubeLiveBroadcastPlayer.GetHTML(liveStream);
                            }
                            else
                            {
                                if (!string.IsNullOrEmpty(liveStream.YouTubeID))
                                {
                                    Response.Redirect(@"https://www.youtube.com/watch?v=" + liveStream.YouTubeID);
                                }
                                else
                                {
                                    displayError("Live stream has no Youtube ID set");
                                }
                            }

                            litStreamInfo.Text = streamInfoBox(liveStream);
                        }
                        else
                        {
                            displayError("This live stream is marked as private. You can only watch from within the LSKYSD network.");
                        }
                    }
                }
                else
                {
                    displayError("A live stream with that ID does not exist.");
                }
            }
            else
            {
                displayError("Stream ID not specified.");
            }
        }