Example #1
0
        private static bool IsScheduleSaved(string new_content, string file_path, string file_name, bool is_user_request)
        {
            string   ext_html = @".html";
            string   ext_png  = @".png";
            FileInfo shedold  = new FileInfo(file_path + file_name + ext_html);

            if (!shedold.Exists)
            {
                System.IO.File.WriteAllText(file_path + file_name + ext_html, "");
            }
            string old_file = System.IO.File.ReadAllText(file_path + file_name + ext_html);

            if ((new_content != old_file) || is_user_request)
            {
                System.IO.File.WriteAllText(file_path + file_name + ext_html, new_content, Encoding.GetEncoding(65001));

                int browser_height = int.Parse(ConfigurationManager.AppSettings["browser_height"]);
                int browser_widht  = int.Parse(ConfigurationManager.AppSettings["browser_widht"]);

                var screenshotJob = ScreenshotJobBuilder.Create(file_path + file_name + ext_html)
                                    .SetBrowserSize(browser_widht, browser_height)
                                    .SetCaptureZone(CaptureZone.VisibleScreen) // Зона захвата
                                    .SetTrigger(new WindowLoadTrigger());      // Set when the picture is taken
                System.IO.File.WriteAllBytes(file_path + file_name + ext_png, screenshotJob.Freeze());
                return(true);
            }
            return(false);
        }
Example #2
0
        // GET: API/Details/5
        public ActionResult ReturnSS()
        {
            var screenShotJob = ScreenshotJobBuilder.Create("DisplayChart", "Home")
                                .SetTransfertRequestCookies(true); // forward session cookies to the capturing browser

            return(screenShotJob.Freeze());
        }
        public void ScreenshotJob_Check_Handling_Of_Timeout()
        {
            var url = $"{_httpServer.BoundURL}/Global/shortpage.html";

            try
            {
                _httpServer.WaitingTime = TimeSpan.FromSeconds(2.5D);

                var screenShotJob = ScreenshotJobBuilder.Create(url)
                                    .SetCaptureZone(CaptureZone.VisibleScreen)
                                    .SetTrigger(new WindowLoadTrigger())
                                    .SetTimeout(TimeSpan.FromSeconds(2D));

                try
                {
                    using ((Image)screenShotJob.Freeze())
                    {
                        Assert.Fail("Freeze() should have thrown an error");
                    }
                }
                catch (CaptureEngineException exception)
                {
                    Assert.AreEqual(exception.State, CaptureEngineState.Timeout);
                }
            }
            finally
            {
                _httpServer.WaitingTime = TimeSpan.Zero;
            }
        }
Example #4
0
        static void Main(string[] args)
        {
            var screenshotJob = ScreenshotJobBuilder.Create("https://github.com")
                                .SetBrowserSize(1366, 768)
                                .SetCaptureZone(CaptureZone.FullPage) // Set what should be captured
                                .SetTrigger(new WindowLoadTrigger()); // Set when the picture is taken

            System.IO.File.WriteAllBytes("this_is_not_even_my_final_screenshot.png", screenshotJob.Freeze());
        }
Example #5
0
        static void Main()
        {
            var screenShotJob = ScreenshotJobBuilder.Create("google.fr")
                                .SetBrowserSize(new Size(640, 1136))
                                .SetTrigger(new WindowLoadTrigger())
                                .SetTimeout(TimeSpan.FromSeconds(30D));

            File.WriteAllBytes("this_is_not_even_my_final_screenshot.png", screenShotJob.Freeze());
        }
Example #6
0
        public void THBQuery(CqGroupMessageEventArgs e, string arg)
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            using (WebClient client = new WebClient())
            {
                XmlDocument document = new XmlDocument();
                XmlReader   reader   = XmlReader.Create(client.OpenRead(THB_QUERY_CMD + arg));
                document.Load(reader);

                var body  = document.LastChild;
                var api   = body.ChildNodes.Item(0);
                var pages = api.ChildNodes.Item(0);
                var page  = pages.ChildNodes.Item(0);

                string result =
                    "----------------" + "\n" +
                    "● " + page.Attributes.GetNamedItem("title").InnerText + "\n" +
                    "----------------" + "\n";
                if (page.ChildNodes.Count > 0)
                {
                    var extract = page.ChildNodes.Item(0);
                    var text    = extract.InnerText.Replace("\n\n", "\n");

                    result += (text + "\n");
                }
                else
                {
                    result += ("么有结果!" + "\n");
                }

                if (result.Length <= 128)
                {
                    Common.CqApi.SendGroupMessage(e.FromGroup, result);
                }
                else
                {
                    Common.CqApi.SendGroupMessage(e.FromGroup, result.Substring(0, 64) + " ... " + result.Substring(128, 64) + " ...");
                    try
                    {
                        var screenshotJob = ScreenshotJobBuilder.Create("https://thwiki.cc/" + arg)
                                            .SetBrowserSize(512, 2048).SetCaptureZone(new CroppedZone(0, 0, 512, 2048)).SetTrigger(new WindowLoadTrigger());
                        Image image = screenshotJob.Freeze();

                        var uuid = Guid.NewGuid().ToString("N");
                        image.Save("data/image/" + uuid + ".png");
                        string cqCode = Common.CqApi.CqCode_Image(uuid + ".png");
                        Common.CqApi.SendGroupMessage(e.FromGroup, cqCode);
                    }
                    catch (Exception ex)
                    {
                        Common.CqApi.SendGroupMessage(e.FromGroup, "图片抓取出错(((");
                    }
                }
            }
        }
Example #7
0
        public byte[] GetScreenShortByUrl(string url)
        {
            var screenshotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(1366, 768)
                                .SetCaptureZone(CaptureZone.FullPage)   // Set what should be captured
                                .SetTrigger(new WindowLoadTrigger(50)); // Set when the picture is taken

            var screen = screenshotJob.Freeze();

            return(screen);
        }
Example #8
0
        // [Option(LongName = "output")]
        // public string output{get; set;}

        public void OnExecute(CommandLineApplication app)
        {
            var imageUrl = urlGambar;
            // var nameFile = output;

            var screenshotJob = ScreenshotJobBuilder.Create(imageUrl)
                                .SetBrowserSize(1366, 768)
                                .SetCaptureZone(CaptureZone.FullPage)
                                .SetTrigger(new WindowLoadTrigger());

            System.Drawing.Image screenshot = screenshotJob.Freeze();
        }
        public void ScreenshotJob_Validate_Bitmap_Size_JQuery_Selector_Long_Page()
        {
            var url = $"{_httpServer.BoundURL}/Global/longpage.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(new JQuerySelectedZone("div"));

            using (var result = (Image)screenShotJob.Freeze())
            {
                Assert.AreEqual(new Size(1080, 2500), result.Size);
            }
        }
        public void ScreenshotJob_Validate_Bitmap_Size_Full_Document()
        {
            var url = $"{_httpServer.BoundURL}/Triggers/simpledocumentload.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(1600, 900)
                                .SetCaptureZone(CaptureZone.FullPage);

            using (var result = (Image)screenShotJob.Freeze())
            {
                Assert.AreEqual(new Size(1584, 97), result.Size);
            }
        }
        public void ScreenshotJob_Validate_Bitmap_Size_Full_Document_Short_Page()
        {
            var url = $"{_httpServer.BoundURL}/Global/shortpage.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(CaptureZone.FullPage);

            using (var result = (Image)screenShotJob.Freeze())
            {
                Assert.AreEqual(new Size(784, 250), result.Size);
            }
        }
        public void ScreenshotJob_Validate_Bitmap_Size_Visible_Screen_Long_Page_With_Scroll()
        {
            var url = $"{_httpServer.BoundURL}/Global/longpage.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(CaptureZone.VisibleScreen);

            using (var result = (Image)screenShotJob.Freeze())
            {
                Assert.AreEqual(new Size(800, 600), result.Size);
            }
        }
        public void ScreenshotJob_Validate_Crop_Zone()
        {
            var url = $"{_httpServer.BoundURL}/Triggers/simpledocumentload.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(1600, 900)
                                .SetCaptureZone(new CroppedZone(0, 0, 25, 156));

            using (var result = (Image)screenShotJob.Freeze())
            {
                Assert.AreEqual(new Size(25, 156), result.Size);
            }
        }
Example #14
0
        public byte[] FreezeScreen(string inputUrl)
        {
            var screenshotJob = ScreenshotJobBuilder.Create("inputUrl")
                                .SetBrowserSize(1366, 768)
                                .SetCaptureZone(CaptureZone.FullPage) // Set what should be captured
                                                                      // .SetTrigger(new WindowLoadTrigger(60)) // Set when the picture is taken
                                .SetTrigger(new DomReadyTrigger(50));

            // document.dispatchEvent(new MessageEvent('FreezerFire'));
            System.IO.File.WriteAllBytes("Screenshot.png", screenshotJob.Freeze());
            byte[] imgSrc = screenshotJob.Freeze();
            return(imgSrc);
        }
        public void ScreenshotJob_Validate_Accept_Languages()
        {
            var url = $"{_httpServer.BoundURL}/Triggers/cookieprinter.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(CaptureZone.VisibleScreen)
                                .SetTrigger(new WindowLoadTrigger())
                                .SetAcceptLanguages("mg,fr;q=0.5");

            using ((Image)screenShotJob.Freeze()) { }

            Assert.AreEqual("mg,fr;q=0.5", string.Join(",", _httpServer.LastAcceptLanguages));
        }
        public void ScreenshotJob_Validate_Document_With_Alert()
        {
            var url = $"{_httpServer.BoundURL}/Global/alertpage.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(1600, 900)
                                .SetCaptureZone(CaptureZone.FullPage)
                                .SetTrigger(new WindowLoadTrigger(100)); // Make sure alert pop up before capture

            using (var result = (Image)screenShotJob.Freeze())
            {
                Assert.AreEqual(new Size(1584, 20), result.Size);
            }
        }
        public void ScreenshotJob_Validate_Bitmap_Size_JQuery_Selector_Out_Of_Scroll_Block()
        {
            var url = $"{_httpServer.BoundURL}/Global/outofscroll.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(new JQuerySelectedZone("#greenblock"));

            using (var result = (Image)screenShotJob.Freeze())
            {
                AssertExtensions.BitmapEquals("ExpectedBitmapsResults/Out_Of_Scroll.png",
                                              result);
            }
        }
        public void ScreenshotJob_Validate_User_Agent()
        {
            var url = $"{_httpServer.BoundURL}/Triggers/cookieprinter.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(CaptureZone.VisibleScreen)
                                .SetTrigger(new WindowLoadTrigger())
                                .SetUserAgent("FakeBrowser");

            using ((Image)screenShotJob.Freeze()) { }

            Assert.AreEqual("FakeBrowser", _httpServer.LastUserAgent);
        }
        public void ScreenshotJob_Validate_Trigger_WindowLoad()
        {
            var url = $"{_httpServer.BoundURL}/Triggers/freezerfiredispatched.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(CaptureZone.VisibleScreen)
                                .SetTrigger(new WindowLoadTrigger(50));

            using (var result = (Image)screenShotJob.Freeze())
            {
                AssertExtensions.BitmapEquals("ExpectedBitmapsResults/Validate_WindowLoad_Event_With_Single_Page.png",
                                              result);
            }
        }
        public void ScreenshotJob_Validate_LocalFile()
        {
            var localFile = new FileInfo("WebPages/Triggers/freezerfiredispatched.html");

            var screenShotJob = ScreenshotJobBuilder.Create(localFile.FullName)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(CaptureZone.VisibleScreen)
                                .SetTrigger(new WindowLoadTrigger(50));

            using (var result = (Image)screenShotJob.Freeze())
            {
                AssertExtensions.BitmapEquals("ExpectedBitmapsResults/Validate_WindowLoad_Event_With_Single_Page.png",
                                              result);
            }
        }
        public void ScreenshotJob_Validate_UserDefinedJavascriptZone()
        {
            var url = $"{_httpServer.BoundURL}/Triggers/simpledocumentload.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(new UserDefinedJavascriptZone("readcoordinate",
                                                                              @"function readcoordinate() {
                      return  {x: 5, y: 25, width: 231, height: 425}; 
                }"));

            using (var result = (Image)screenShotJob.Freeze())
            {
                Assert.AreEqual(new Size(231, 425), result.Size);
            }
        }
        public void ScreenshotJob_Validate_Cookie_Transfert()
        {
            var url = $"{_httpServer.BoundURL}/Triggers/cookieprinter.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(CaptureZone.VisibleScreen)
                                .SetTrigger(new WindowLoadTrigger())
                                .AddCookie(new Cookie("127.0.0.1", "/", "FreezerCookie", "FreezerCookieValue"));

            using ((Image)screenShotJob.Freeze()) { }

            var cookieValue = _httpServer.LastCookies
                              .First(c => c.Name == "FreezerCookie").Value;

            Assert.AreEqual("FreezerCookieValue", cookieValue);
        }
        public void ScreenshotJob_Validate_JQuery_Zero_Width_Container()
        {
            var url = $"{_httpServer.BoundURL}/Triggers/freezerfiredispatched.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetCaptureZone(new JQuerySelectedZone("#zerowidthcontainer"));

            try
            {
                using ((Image)screenShotJob.Freeze())
                {
                    Assert.Fail("Freeze() should have thrown an error");
                }
            }
            catch (CaptureEngineException exception)
            {
                Assert.AreEqual(exception.State, CaptureEngineState.InvalidCaptureZone);
            }
        }
        public void ScreenshotJob_Validate_Crop_Zone_Out_Of_Bounds()
        {
            var url = $"{_httpServer.BoundURL}/Triggers/simpledocumentload.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(1024, 768)
                                .SetCaptureZone(new CroppedZone(900, 0, 400, 156));

            try
            {
                using ((Image)screenShotJob.Freeze())
                {
                    Assert.Fail("Freeze() should have thrown an error");
                }
            }
            catch (CaptureEngineException exception)
            {
                Assert.AreEqual(exception.State, CaptureEngineState.InvalidCaptureZone);
            }
        }
        public void ScreenshotJob_Validate_Bitmap_Size_JQuery_Selector_Invalid_Container()
        {
            var url = $"{_httpServer.BoundURL}/Global/shortpage.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(new JQuerySelectedZone("#nonexistentcontainer"));

            try
            {
                using ((Image)screenShotJob.Freeze())
                {
                    Assert.Fail("Freeze() should have thrown an error");
                }
            }
            catch (CaptureEngineException exception)
            {
                Assert.AreEqual(exception.State, CaptureEngineState.InvalidCaptureZone);
            }
        }
        public void ScreenshotJob_Check_Handling_Of_Invalid_DNS()
        {
            var url = "http://ishouldnotitdomainnameppm.biz:8152";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(1600, 900)
                                .SetCaptureZone(CaptureZone.VisibleScreen)
                                .SetTrigger(new WindowLoadTrigger());

            try
            {
                using ((Image)screenShotJob.Freeze())
                {
                    Assert.Fail("Freeze() should have thrown an error");
                }
            }
            catch (CaptureEngineException exception)
            {
                Assert.AreEqual(exception.State, CaptureEngineState.NavigationError);
            }
        }
        public void ScreenshotJob_Check_Handling_Of_Connection_Refused()
        {
            var url = "http://127.0.0.8:1";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(1600, 900)
                                .SetCaptureZone(CaptureZone.VisibleScreen)
                                .SetTrigger(new WindowLoadTrigger());

            try
            {
                using ((Image)screenShotJob.Freeze())
                {
                    Assert.Fail("Freeze() should have thrown an error");
                }
            }
            catch (CaptureEngineException exception)
            {
                Assert.AreEqual(exception.State, CaptureEngineState.NavigationError);
            }
        }
Example #28
0
        public string readWebDate(string wURL)
        {
            string          sourceCode = "";
            HttpWebRequest  request    = (HttpWebRequest)WebRequest.Create(WebURL);
            HttpWebResponse response   = (HttpWebResponse)request.GetResponse();
            StreamReader    sr         = new StreamReader(response.GetResponseStream());

            sourceCode = sr.ReadToEnd();
            try
            {
                /*
                 * Genero el screenshot con la libreria Freezer
                 * Para despues comparar
                 */
                var screenshotJob = ScreenshotJobBuilder.Create(WebURL)
                                    .SetBrowserSize(600, 300)
                                    .SetCaptureZone(CaptureZone.VisibleScreen)
                                    .SetTrigger(new WindowLoadTrigger());

                System.Drawing.Image screenshot = screenshotJob.Freeze();
                Random rnd = new Random();
                screenshot.Save("c:/imgWebPhishing/" + rnd.Next(1, 100) + ".png", ImageFormat.Png);
                screenshot.Dispose();

                /*
                 * Guardo los datos de certificado si los tiene
                 */
                X509Certificate  cert  = request.ServicePoint.Certificate;
                X509Certificate2 cert2 = new X509Certificate2(cert);
                string           cn    = cert2.GetIssuerName();
                SSL_EXPIRATION_DATE = Convert.ToDateTime(cert2.GetExpirationDateString());
                SSL_KEY             = cert2.GetPublicKeyString();
            }
            catch (Exception)
            {}
            sr.Close();
            response.Close();
            return(sourceCode);
        }
        public void ScreenshotJob_Validate_UserDefinedJavascriptZone_BadJavascriptImplementation()
        {
            var url = $"{_httpServer.BoundURL}/Triggers/simpledocumentload.html";

            var screenShotJob = ScreenshotJobBuilder.Create(url)
                                .SetBrowserSize(800, 600)
                                .SetCaptureZone(new UserDefinedJavascriptZone("readcoordinate",
                                                                              @"bad function readcoordinate() {
                      return  {x: 5, y: 56, width: 231, height: 425}; 
                }"));

            try
            {
                using ((Image)screenShotJob.Freeze()) { }

                Assert.Fail("Freeze() should have thrown an error");
            }
            catch (CaptureEngineException exception)
            {
                Assert.AreEqual(exception.State, CaptureEngineState.InvalidCaptureZone);
            }
        }
        public IActionResult Index(string urlString)
        {
            byte[] imageAsBytes = null;

            var    splitHostName = urlString.Split('.');
            string siteName      = splitHostName[1];


            var screenshotJob = ScreenshotJobBuilder.Create(urlString)
                                .SetBrowserSize(1366, 768)
                                .SetCaptureZone(CaptureZone.VisibleScreen) // Set what should be captured
                                .SetTrigger(new WindowLoadTrigger())
                                .Freeze();                                 // Set when the picture is taken

            imageAsBytes = screenshotJob.AsBytes();


            blobstorenet.sendByteArrayToBlob(siteName, imageAsBytes);

            //System.IO.File.WriteAllBytes($"D:\\{siteName}.jpg", imageAsBytes);

            return(View());
        }