Ejemplo n.º 1
0
        //TODO: This should be retrieved from a Queue via API or Messaging.
        //TODO: ReportProcessingCount should be retrieved from a settings table on the server and not hard coded.
        internal static EUReported GetNextUnprocessedRecord()
        {
            Damocles2Entities de  = new Damocles2Entities();
            EUReported        eur = de.EUReporteds.Where(r => r.Processed == false && r.ReportProcessingCount < 11).FirstOrDefault();

            return(eur);
        }
Ejemplo n.º 2
0
        //TODO: Should probably be extracted to a separate class

        /// <summary>
        /// Process the first most important Unprocessed Report
        /// </summary>
        /// <param name="eur">
        /// Class: EUReported record
        /// </param>
        private void ProcessUnReported(EUReported eur)
        {
            Imogen.Controllers.Reporting.CurrentInternalReport.Reset();
            DownloadImage di = new DownloadImage();

            Log("Loading Processing of New Report"); // This could be a partial report so check the other tables as well !!
            CurrentInternalReport.PageUrlHash = eur.PageUrlHash;
            CurrentInternalReport.PageUrl     = eur.PageUrl;
            CurrentInternalReport.SrcUrlHash  = eur.SrcUrlHash;
            CurrentInternalReport.SrcUrl      = eur.SrcUrl;


            CurrentInternalReport.LinkUrlHash     = eur.LinkUrlHash;
            CurrentInternalReport.LinkUrl         = eur.LinkUrl;
            CurrentInternalReport.ReportNumber    = eur.id;
            CurrentInternalReport.ReportedOn      = eur.CreatedOn;
            CurrentInternalReport.SrcUrlFilename  = utils.GetPossibleFileName(eur.SrcUrl);
            CurrentInternalReport.LinkUrlFilename = utils.GetPossibleFileName(eur.LinkUrl);

            Log("Downloading Image");
            string imgPath = di.Download(eur.SrcUrl);

            if (imgPath != null)
            {
                Log("Download Completed", LogType.Success);
                frmProfileImage.ShowImage(imgPath);
                currentFilePath = imgPath;
                CurrentInternalReport.ImagePath = imgPath;
            }
            else
            {
                Log("Download Failed", LogType.Error);
            }

            // Shows the Src Image and Metadata
            Log("Opening Restricted Web Browser for Src Url");
            try
            {
                if (frmRWB == null)
                {
                    frmRWB.Show(dockPanel, DockState.Document);
                }
                frmRWB.ShowSrcUrl(eur.SrcUrl);
                if (frmMetadata == null)
                {
                    frmMetadata.Show(dockPanel, DockState.DockRight);
                }
                frmMetadata.GetMetaData(currentFilePath);
            }
            catch (Exception ex)
            {
                Log(ex.Message, LogType.Error);
                throw;
            }
        }
Ejemplo n.º 3
0
        // This is a 404 or some other error - do a check for a month to see if it returns
        // This can be done within Imogen as Background House keeping
        internal void SetLinkToGoneButNotForgotten(string url)
        {
            Damocles2Entities de = new Damocles2Entities();

            string pHash = hh.GetSHA512(CurrentUser.UserPassword);
            User   usr   = de.Users.Where(u => u.Username == CurrentUser.Username && u.UserPassword == pHash).FirstOrDefault();

            EUReported eu = de.EUReporteds.Where(l => l.LinkUrl == url).FirstOrDefault();

            if (!string.IsNullOrEmpty(CurrentInternalReport.TrueLinkUrl))
            {
                eu.TrueLinkUrl = CurrentInternalReport.TrueLinkUrl;
            }
            if (!string.IsNullOrEmpty(CurrentInternalReport.TrueLinkUrlHash))
            {
                eu.TrueLinkUrlHash = CurrentInternalReport.TrueLinkUrlHash;
            }
            eu.UpdatedOn = DateTime.UtcNow;

            GoneButNotForgottenLink gb = new GoneButNotForgottenLink();

            gb.CreatedOn     = DateTime.UtcNow;
            gb.Id            = eu.id;
            gb.LastCheckedOn = DateTime.UtcNow;
            gb.LinkUrlHash   = eu.LinkUrlHash;
            gb.ReportedBy    = usr.Id;

            //TODO: This won't work - we don't know which link is GoneButNotForgotten - the redirection link or the TrueLink.
            if (!string.IsNullOrEmpty(CurrentInternalReport.TrueLinkUrlHash))
            {
                eu.TrueLinkUrlHash = CurrentInternalReport.TrueLinkUrlHash;
            }


            de.GoneButNotForgottenLinks.Add(gb);
            try
            {
                de.SaveChanges();
            }
            catch (Exception)
            {
            }


            de.Dispose();
            gb  = null;
            eu  = null;
            usr = null;
        }
Ejemplo n.º 4
0
        internal void SetSrcToGoneButNotForgotten(string url)
        {
            Damocles2Entities de = new Damocles2Entities();
            User usr             = GetUser(de);

            EUReported eu = de.EUReporteds.Where(l => l.SrcUrl == url).FirstOrDefault();

            eu.UpdatedOn = DateTime.UtcNow;

            GoneButNotForgottenLink gb = new GoneButNotForgottenLink();

            gb.CreatedOn     = DateTime.UtcNow;
            gb.Id            = eu.id;
            gb.LastCheckedOn = DateTime.UtcNow;
            gb.SrcUrlHash    = eu.SrcUrlHash;
            gb.ReportedBy    = usr.Id;
            de.GoneButNotForgottenLinks.Add(gb);
            de.SaveChanges();

            de.Dispose();
            gb  = null;
            eu  = null;
            usr = null;
        }
Ejemplo n.º 5
0
        private void GenerateReportedSelectedTextTables(string pageUrl, string pageUrlHash, string selectionText, string selectionTextHash, ReportItEntities rie, SelectionText st, ReportedSelectedText rst)
        {
            if (!string.IsNullOrEmpty(selectionText))
            {
                // Does the pageUrl exist?
                // Does the srcUrl exist?
                // Do they both exist in the ReportedSrcUrls table? They should be it is nice to have a sanity check
                EUReported puRecord = GetPageUrlRecord(rie, pageUrlHash);
                if (puRecord == null)
                {
                    // The page record has never been created
                    // Create Page Record
                    puRecord             = new EUReported();
                    puRecord.Count       = 1;
                    puRecord.PageUrl     = pageUrl;
                    puRecord.PageUrlHash = pageUrlHash;
                    puRecord.Processed   = false;
                    puRecord.CreatedOn   = DateTime.UtcNow;
                    puRecord.UpdatedOn   = DateTime.UtcNow;
                    rie.EUReporteds.Add(puRecord);
                }
                else
                {
                    // The page record has been created - update count
                    puRecord.Count     = puRecord.Count + 1;
                    puRecord.UpdatedOn = DateTime.UtcNow;
                }

                // Ok now check to see if the SrcUrl exists
                st = GetSelectionTextRecord(rie, selectionTextHash);
                if (st == null)
                {
                    // The SrcUrl record has never been created
                    // Create SrcUrl record
                    st                   = new SelectionText();
                    st.Count             = 1;
                    st.Processed         = false;
                    st.SelectionText1    = selectionText;
                    st.SelectionTextHash = selectionTextHash;
                    st.CreatedOn         = DateTime.UtcNow;
                    st.UpdatedOn         = DateTime.UtcNow;
                    rie.SelectionTexts.Add(st);
                }
                else
                {
                    // The srcUrl record has been created - update count
                    st.Count     = st.Count + 1;
                    st.UpdatedOn = DateTime.UtcNow;
                }


                // Ok Now the Sanity Check to make sure that the Many to Many table is correctly populated
                if (!ReportedSelectedTextExists(rie, pageUrlHash, selectionTextHash))
                {
                    rst.PageUrlHash      = pageUrlHash;
                    rst.SelectedTextHash = selectionTextHash;
                    rie.ReportedSelectedTexts.Add(rst);
                }
                rie.SaveChanges();
            }
        }
Ejemplo n.º 6
0
        // POST api/Reports
        public void Post([FromBody] string value)
        {
            // Parts received separated by ,
            // PageUrl          -- The Url of the page being reported [0]
            // SrcUrl           -- The SrcUrl of any Image being reported [1]
            // LinkUrl          -- The Url of any link that is being reported [2]
            // SelectionText    -- Any Text that is being reported [3..n]

            try
            {
                if (value != null)
                {
                    // Get the Reported values and Hashes of them
                    string pu          = GetPageUrl(value);
                    string pageUrlHash = GetSHA512(pu);
                    string pageUrl     = Security.Encrypt(pu, pageUrlHash);
                    string srcUrl      = Security.Encrypt(GetSrcUrl(value), pageUrlHash);
                    //string pageUrl = pu;
                    //string srcUrl = GetSrcUrl(value);

                    string srcUrlHash = null;
                    if (!string.IsNullOrEmpty(srcUrl))
                    {
                        srcUrlHash = GetSHA512(srcUrl);
                    }

                    string lulu        = GetLinkUrl(value);
                    string linkUrlHash = null;
                    if (!string.IsNullOrEmpty(lulu))
                    {
                        linkUrlHash = GetSHA512(lulu);
                    }
                    string linkUrl = Security.Encrypt(lulu, linkUrlHash);
                    //string linkUrl = lulu;

                    string stst = GetSelectionText(value);
                    string selectionTextHash = null;
                    if (!string.IsNullOrEmpty(stst))
                    {
                        selectionTextHash = GetSHA512(stst);
                    }
                    string selectionText = Security.Encrypt(stst, selectionTextHash);
                    //string selectionText = stst;

                    ReportItEntities rie = new ReportItEntities();
                    rie.Database.Connection.Open(); // Connect to the Database

                    // Generate our tables
                    EUReported           eur = new EUReported();
                    SrcUrl               su  = new SrcUrl();
                    ReportedSrcUrl       rsu = new ReportedSrcUrl();
                    LinkUrl              lu  = new LinkUrl();
                    ReportedLinkUrl      rlu = new ReportedLinkUrl();
                    SelectionText        st  = new SelectionText();
                    ReportedSelectedText rst = new ReportedSelectedText();


                    if (!string.IsNullOrEmpty(pageUrl))
                    {
                        GenerateReportedSrcsTables(pageUrl, pageUrlHash, srcUrl, srcUrlHash, rie, su, rsu);
                        GenerateReportedLinksTables(pageUrl, pageUrlHash, linkUrl, linkUrlHash, rie, lu, rlu);
                        GenerateReportedSelectedTextTables(pageUrl, pageUrlHash, selectionText, selectionTextHash, rie, st, rst);
                    }
                    else
                    {
                        //Just drop out the bottom -no PageUrl == nothing to process
                    }

                    rie.Database.Connection.Close();
                }
                // return "Nothing received";
            }
            catch (Exception)
            {
                // return ex.InnerException.ToString();
            }
        }
Ejemplo n.º 7
0
        private void GenerateReportedLinksTables(string pageUrl, string pageUrlHash, string linkUrl, string linkUrlHash, ReportItEntities rie, LinkUrl lu, ReportedLinkUrl rlu)
        {
            if (!string.IsNullOrEmpty(linkUrl))
            {
                // Does the pageUrl exist?
                // Does the srcUrl exist?
                // Do they both exist in the ReportedSrcUrls table? They should be it is nice to have a sanity check
                EUReported puRecord = GetPageUrlRecord(rie, pageUrlHash);
                if (puRecord == null)
                {
                    // The page record has never been created
                    // Create Page Record
                    puRecord             = new EUReported();
                    puRecord.Count       = 1;
                    puRecord.PageUrl     = pageUrl;
                    puRecord.PageUrlHash = pageUrlHash;
                    puRecord.Processed   = false;
                    puRecord.CreatedOn   = DateTime.UtcNow;
                    puRecord.UpdatedOn   = DateTime.UtcNow;
                    rie.EUReporteds.Add(puRecord);
                }
                else
                {
                    // The page record has been created - update count
                    puRecord.Count     = puRecord.Count + 1;
                    puRecord.UpdatedOn = DateTime.UtcNow;
                }

                // Ok now check to see if the SrcUrl exists
                lu = GetLinkUrlRecord(rie, linkUrlHash);
                if (lu == null)
                {
                    // The SrcUrl record has never been created
                    // Create SrcUrl record
                    lu             = new LinkUrl();
                    lu.Count       = 1;
                    lu.Processed   = false;
                    lu.LinkUrl1    = linkUrl;
                    lu.LinkUrlHash = linkUrlHash;
                    lu.CreatedOn   = DateTime.UtcNow;
                    lu.UpdatedOn   = DateTime.UtcNow;
                    rie.LinkUrls.Add(lu);
                }
                else
                {
                    // The srcUrl record has been created - update count
                    lu.Count     = lu.Count + 1;
                    lu.UpdatedOn = DateTime.UtcNow;
                }


                // Ok Now the Sanity Check to make sure that the Many to Many table is correctly populated
                if (!ReportedLinkUrlsExists(rie, pageUrlHash, linkUrlHash))
                {
                    rlu.PageUrlHash = pageUrlHash;
                    rlu.LinkUrlHash = linkUrlHash;
                    rie.ReportedLinkUrls.Add(rlu);
                }
                rie.SaveChanges();
            }
        }
Ejemplo n.º 8
0
        internal void SetSrcToCriminal(string url)
        {
            Damocles2Entities de = new Damocles2Entities();

            User usr = GetUser(de);

            EUReported eu = de.EUReporteds.Where(l => l.SrcUrl == url).FirstOrDefault();


            // Create ProcessingResult table if it does not already exist!
            var pr = de.ProcessingResults.Where(prr => prr.id == eu.id).FirstOrDefault();

            bool Update = true;

            if (pr == null)
            {
                Update = false;
                pr     = new ProcessingResult();
            }

            pr.id = eu.id;
            var uju = de.UserJurisdictions.Where(uj => uj.UserId == usr.Id).FirstOrDefault();

            pr.JurisdictionId = uju.JurisdictionID;
            pr.CreatedOn      = DateTime.UtcNow;
            pr.UpdatedOn      = DateTime.UtcNow;
            pr.UserId         = usr.Id;

            // Only add records if they have not already been created (for just now)
            //if (pr.ASrcResultId == null)
            //{
            //    A aRecord = new A();
            //    aRecord.ResultCount = aRecord.ResultCount + 1;
            //    aRecord.UpdatedOn = DateTime.UtcNow;
            //    aRecord.CreatedOn = DateTime.UtcNow;
            //    aRecord.IsAllowed = true;
            //    de.A.Add(aRecord);
            //    pr.ASrcResultId = aRecord.pid;
            //}

            //if (pr.RSrcResultId == null)
            //{
            //    R rRecord = new R();
            //    rRecord.ResultCount = rRecord.ResultCount + 1;
            //    rRecord.UpdatedOn = DateTime.UtcNow;
            //    rRecord.CreatedOn = DateTime.UtcNow;
            //    rRecord.IsRestricted = true;
            //    de.R.Add(rRecord);
            //    pr.RSrcResultId = rRecord.pid;
            //}

            if (pr.CSrcResultId == null)
            {
                C cRecord = new C();
                cRecord.ResultCount = cRecord.ResultCount + 1;
                cRecord.UpdatedOn   = DateTime.UtcNow;
                cRecord.CreatedOn   = DateTime.UtcNow;
                cRecord.IsCriminal  = true;
                de.C.Add(cRecord);
                pr.CSrcResultId = cRecord.pid;
            }

            if (!Update)
            {
                de.ProcessingResults.Add(pr);
            }

            // Check to see if the LinkUrl is GoneButNotForgotten
            var gbnf = de.GoneButNotForgottenLinks.Where(gbn => gbn.LinkUrlHash == eu.LinkUrlHash).FirstOrDefault();

            if (gbnf != null)
            {
                eu.Processed = true;
            }
            else
            {
                // this record had already been created so we may have to mark EU as processed - check now
                if (pr.ALinkResultId != null || pr.RLinkResultId != null || pr.CLinkResultId != null)
                {
                    eu.Processed = true;
                }
            }

            eu.UpdatedOn = DateTime.UtcNow;
            de.SaveChanges();

            //TODO: Implement this
            // if eu.Processed == true then raise Event to tell frmMain to go to the next unprocessed Report
        }