From cbe73fa13f16082b4ab36ded7820acbc7d86abbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Wed, 24 Aug 2022 14:04:47 +0200 Subject: [PATCH] fix: better handling of downloaded content from URL --- lookyloo/lookyloo.py | 33 ++++++++++++++++++-------------- website/web/sri.txt | 3 ++- website/web/static/download.png | Bin 0 -> 1457 bytes website/web/static/tree.js | 2 +- 4 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 website/web/static/download.png diff --git a/lookyloo/lookyloo.py b/lookyloo/lookyloo.py index a6766dc..14a6794 100644 --- a/lookyloo/lookyloo.py +++ b/lookyloo/lookyloo.py @@ -521,20 +521,25 @@ class Lookyloo(): '''Get the thumbnail of the rendered page. Always crop to a square.''' to_return = BytesIO() size = width, width - try: - s = self.get_screenshot(capture_uuid) - orig_screenshot = Image.open(s) - to_thumbnail = orig_screenshot.crop((0, 0, orig_screenshot.width, orig_screenshot.width)) - except Image.DecompressionBombError as e: - # The image is most probably too big: https://pillow.readthedocs.io/en/stable/reference/Image.html - self.logger.warning(f'Unable to generate the screenshot thumbnail of {capture_uuid}: image too big ({e}).') - error_img: Path = get_homedir() / 'website' / 'web' / 'static' / 'error_screenshot.png' - to_thumbnail = Image.open(error_img) - except UnidentifiedImageError as e: - # The image is most probably too big: https://pillow.readthedocs.io/en/stable/reference/Image.html - self.logger.warning(f'Unable to generate the screenshot thumbnail of {capture_uuid}: image too big ({e}).') - error_img = get_homedir() / 'website' / 'web' / 'static' / 'error_screenshot.png' - to_thumbnail = Image.open(error_img) + filename, data = self.get_data(capture_uuid) + if filename: + download_img: Path = get_homedir() / 'website' / 'web' / 'static' / 'download.png' + to_thumbnail = Image.open(download_img) + else: + try: + s = self.get_screenshot(capture_uuid) + orig_screenshot = Image.open(s) + to_thumbnail = orig_screenshot.crop((0, 0, orig_screenshot.width, orig_screenshot.width)) + except Image.DecompressionBombError as e: + # The image is most probably too big: https://pillow.readthedocs.io/en/stable/reference/Image.html + self.logger.warning(f'Unable to generate the screenshot thumbnail of {capture_uuid}: image too big ({e}).') + error_img: Path = get_homedir() / 'website' / 'web' / 'static' / 'error_screenshot.png' + to_thumbnail = Image.open(error_img) + except UnidentifiedImageError as e: + # The image is most probably too big: https://pillow.readthedocs.io/en/stable/reference/Image.html + self.logger.warning(f'Unable to generate the screenshot thumbnail of {capture_uuid}: {e}.') + error_img = get_homedir() / 'website' / 'web' / 'static' / 'error_screenshot.png' + to_thumbnail = Image.open(error_img) to_thumbnail.thumbnail(size) to_thumbnail.save(to_return, 'png') diff --git a/website/web/sri.txt b/website/web/sri.txt index e3d3c17..959a717 100644 --- a/website/web/sri.txt +++ b/website/web/sri.txt @@ -12,6 +12,7 @@ "datatables.min.js": "VUgHTv8zUr1K/xtRWvjLwZx2RiyuMfhxefJuDMNFQ2KYT9Y/qGKxgLJ2PBSQzyqbb9uoCzYzccAeF2hC7Qa91Q==", "down.jpg": "LHRHJ5yCaSjNcDfEoChGIfh7K5HrMYbaGn7EOlxgZ8GoLIwb0nFBkpoOMG9gMHA/pBX2skkXMukvKJC6P6FBGg==", "down_left.jpg": "UwHkJaZGayY1LewuFM3bJHQCUPG1vYyrVeiGG5mCM9MD9FtAhdbD4hBY3JZNDWv93CXeEAbxL1kqEeHTKnyquQ==", + "download.png": "A0K7cyVs9BtVjVBEBJtbWYzdKRCp+HIHRO9S0PKe/VrhCMk5Z90J64F794Q/g1H8NoeUSB0KV545kOQWl9BaOw==", "empty.svg": "6tfMLNzDFV9P6t1rC2tDRQtOGzrxi/VtIBc8aV0jo4i3u+dn1fIe3/fySBFA6z13n+XjISF5bTRUNBsN3LWinQ==", "error_screenshot.png": "IkUKnQ47PYYreukA7Byvx+5ACkcCvqk+jYD0GZoQznsD9qDPWrKAMZxlIku7G3Re19vehIlYawep/THcV/ruTA==", "exe.png": "pWwo9nBLtEss/UJ173zHa6/RpySUyz/XMdNhWc6aRIvwwHMO6a+fLmu2K6TbvO3Jbg4VYL2Af4yhHPyhH3ZeTw==", @@ -34,7 +35,7 @@ "stats.css": "/kY943FwWBTne4IIyf7iBROSfbGd82TeBicEXqKkRwawMVRIvM/Pk5MRa7okUyGIxaDjFQGmV/U1vy+PhN6Jbw==", "stats_graph.js": "0OEouA6NAxLG2wMd7D2vtGoMrXKna7My98Euc6ecyfdO4/6mIJS87vzISOS4zSZ8u4ehpa+p7E0nWhsXXE7H/Q==", "tree.css": "THJ9LnnSJ91DSTvrYoOCxRrenGgwsgG5zKo+eZLH2rRFHn6lpX9UpmRhRic4th9ZYuM9/NJUS7LqYBDRPPnB1Q==", - "tree.js": "H6ibjUxG7eD+Dz+jFBnERtxTIdR1aPssd86rCrwHH8CHUySn70aCE3mCmGYwNWw0GCpGT1IYWuZ+K0us+selNg==", + "tree.js": "GU+5QryGm9FqVNFqPPmw872HA5xCJ30fW2QBe7zkZs89bmMnk7eU1TohmkJ/GKODacjyKvMJ3q/Yfjh3F4gAjQ==", "up.jpg": "d1ljZJ9f5JekyM6RLFFH2Ua44j6neiQBdUIXOenRTjGppQr3JaeglpQIH6BjPCJL177+TH52U3UIRNS5YAyKIg==", "up_right.jpg": "OMmz+n+MxR34P8/fn5t4DkqKqdJRzQbXQ7fAi2lhkZIJGhVs2vIyY1f2hpYoBxDAX1OcYsSE2lqIR2vXNDGZsA==", "video.png": "gJtmkfr8I1Kw43pYEKjg6CAjgmhl1vIBKBQ3ZkxCu3wvxQm+6kf93iLrrFiY2WuiXzxEn2Leu52GJzmVN5id0g==", diff --git a/website/web/static/download.png b/website/web/static/download.png new file mode 100644 index 0000000000000000000000000000000000000000..a82848e78c8459ad24e27b86099147b3149bc468 GIT binary patch literal 1457 zcmeAS@N?(olHy`uVBq!ia0vp^A3&Ic1xQYbQIrHyEa{HEjtmSN`?>!lvI6-E$sR$z z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBD8ZEE?e4V&TnW)hyI3 zd3rj^Rs3B`$Af!Q>l@Yu3C3tm`^Ou*!-P@0Y4(z}Ug6ukgf|9mP(0##{d1A=_osJ^ z=ci9Ip1Ev)`nxYPt)Jfkx)K6PPJ3;w-z+@YW0G;)<5FjXg9;KX%?ScLO^!I29BOa{ zIGAh)VJ2{(GNl>GGTkul;Pj$PFV||`{bv?^`uioT*{fywx6ZkJb&hP-8Es~*xYK3V zraxF(V=HYL;dbz3)wa!HJMT5;Jo)v>?7&f((7(@WrgR_Xt0+x4xIfK)edr&ie;VOa z{w&Svzpq=A{q7~>?VTpqHigfe zdr9cqJ6}x=k6phUU3zwZ%0cHZCHLR%xzhCe{mXy1D^Ie1zkS(x%jZkn@76DG&rENs ze*H4>*31Xa?^J%p*;ou)Axo?c)(h{>&xpLfjt5K)9dH* zHi^G@X&95<{2=)I7mIb99Y1JRSLs~8nUVQVJNREi+M1rEoY|iHBsw32J=>qtbllnd zvwiX;Vp8fPpPNmk_Wb5m%Y+ZhO!z-b{$TquGo^Q?;x!3b%8%ARYpOTgDpWQlQhLn_uo8mQK@P2^J3lp*(noco;^MJd_$W1HRil$e`RK; zHp)D|8(Ee9SNc!G-8<)IKZ}%5|EVxN-9D#uo%-%+(Upf^^)KqXclM{mwr4}XCV>sI52d9Q#%swJ)wB`Jv| zsaDBFsX&Us$iT=z*T7iU$S}mf+{)0>%EVaPz`)ADK;a6z1&W5;{FKbJO57R(JNE<2 PSOx}9S3j3^P6 d3.select('#tooltip').style('opacity', 0)); - } else if (d.data.all_empty) { + } else if (d.data.all_empty && !d.data.contains_rendered_urlnode) { // set empty d3.select(this).append("svg").append('rect') .attr('x', selected_node_bbox.width - 22 - http_icon_size)