Commit 6bf594654d

6bf594654d9a442014eb6b7b1a64ef507c5210d2

parent: a799fab9b0

Unsigned

Alicia Sykes <alicia@omg.lol> · 2024-02-29 21:07 UTC

Writes componenent to display detailed website metrics of a given service

Layout: unified · split

web/src/components/things/WebsiteDetailedInfo.astro added +329
@@ -0,0 +1,329 @@
1---
2
3import type { WebsiteData } from '@utils/fetch-website-info';
4import { analyzeSecurityChecks } from '@utils/security-check-mappings';
5import FontAwesome from "@components/form/FontAwesome.svelte"
6import Button from '@components/form/Button.astro';
7
8interface Props {
9 websiteInfo: WebsiteData;
10 url: string;
11};
12
13const { websiteInfo, url } = Astro.props;
14
15const categoryLabels: {[key: string]: string} = {
16 is_torrent: 'Torrenting',
17 is_vpn_provider: 'VPN Provider',
18 is_free_hosting: 'Free Hosting',
19 is_anonymizer: 'Anonymizer',
20 is_url_shortener: 'URL Shortner',
21 is_free_dynamic_dns: 'Free Dynamic DNS',
22 is_code_sandbox: 'Code Sandbox',
23 is_form_builder: 'Form Builder',
24 is_free_file_sharing: 'File Sharing',
25 is_pastebin: 'Pastebin'
26};
27
28const siteCategories = Object.entries(websiteInfo.site_category)
29 .filter(([key, value]) => value)
30 .map(([key]) => categoryLabels[key]);
31
32const securityChecks = analyzeSecurityChecks(websiteInfo.security_checks);
33
34const risk = websiteInfo.risk_score.result;
35let riskText = 'unknown';
36if (risk < 5) riskText = 'safe';
37else if (risk < 15) riskText = 'moderately safe';
38else if (risk < 50) riskText = 'risky';
39else if (risk < 75) riskText = 'dangerous';
40else if (risk >= 75) riskText = 'very dangerous';
41
42
43const clientSideKey = 'cd02a8520c90410bbc32440950bd3b7e';
44const screenshotOptions = 'format=png&width=960&height=540&ttl=2419200&response_type=image&no_cookie_banners=true&no_ads=true';
45const screenshotEndpoint = 'https://api.apiflash.com/v1';
46const screenshotUrl = `${screenshotEndpoint}/urltoimage?access_key=${clientSideKey}&url=${encodeURIComponent(url)}&${screenshotOptions}`;
47
48---
49
50<div class="website-info-wrapper">
51 <div class="left">
52 <h4>Website</h4>
53 <p class="website-title">
54 <img src={`https://favicone.com/${websiteInfo.url_parts.host}`} width="16" />
55 {websiteInfo.web_page.title}
56 </p>
57 <p class="website-description">{websiteInfo.web_page.description}</p>
58 <h4>Redirects</h4>
59 {websiteInfo.redirection.found ? (
60 <p>
61 <FontAwesome iconName="redirectFound" />
62 Redirects to {websiteInfo.redirection.url}
63 </p>
64 ) : (
65 <p class="all-good">
66 <FontAwesome iconName="redirectNotFound" />
67 Does not redirect
68 </p>
69 )}
70 <h4>Security Checks</h4>
71 { securityChecks.failedChecks.length > 0 ? (
72 <>
73 <p class="explainer">
74 {securityChecks.failedChecks.length} security checks failed ({securityChecks.passedChecks.length} passed)
75 </p>
76 <ul>
77 {securityChecks.failedChecks.map((check) => (
78 <li class="all-bad">
79 <FontAwesome iconName="blacklistFound" /> {check}
80 </li>
81 ))}
82 </ul>
83 </>
84 ) : (
85 <p class="all-good">
86 <FontAwesome iconName="redirectNotFound" />
87 All {securityChecks.passedChecks.length} security checks passed
88 </p>
89 )}
90 <h4>Server Details</h4>
91 <ul class="list-table">
92 <li>
93 <span class="lbl">IP Address</span>
94 <span class="val">{websiteInfo.server_details.ip}</span>
95 </li>
96 {websiteInfo.server_details.hostname && (
97 <li>
98 <span class="lbl">Hostname</span>
99 <span class="val">{websiteInfo.server_details.hostname}</span>
100 </li>
101 )}
102 <li>
103 <span class="lbl">Location</span>
104 <span class="val">
105 {websiteInfo.server_details.city_name},
106 {websiteInfo.server_details.region_name},
107 {websiteInfo.server_details.country_name},
108 {websiteInfo.server_details.continent_code}
109 </span>
110 </li>
111 <li>
112 <span class="lbl">ISP</span>
113 <span class="val">{websiteInfo.server_details.isp}</span>
114 </li>
115 <li>
116 <span class="lbl">ASN</span>
117 <span class="val">{websiteInfo.server_details.asn}</span>
118 </li>
119 </ul>
120
121 {siteCategories.length > 0 && (
122 <h4>Categories</h4>
123 <p class="explainer">Some proxies may block this service, as it falls into the following categories</p>
124 <ul>
125 {siteCategories.map((category) => (
126 <li>{category}</li>
127 ))}
128 </ul>
129 )}
130 <h4>Associated Countries</h4>
131 <ul>
132 {websiteInfo.geo_location.countries.map((country) => (
133 <li>
134 <img width="16" src={`https://flagcdn.com/48x36/${country.toLowerCase()}.png`} />
135 {country}
136 </li>
137 ))}
138 </ul>
139 <h4>Saftey Score</h4>
140 <p class="explainer">Website marked as {riskText}</p>
141 <div class={`risk risk-${riskText.replaceAll(' ', '-').toLocaleLowerCase()}`}>
142 <p>{100-risk}%</p>
143 </div>
144 </div>
145 <div class="right">
146 <h4>Blacklist Check</h4>
147 <p>{websiteInfo.url_parts.host} was found on <b>{websiteInfo.domain_blacklist.detections}</b> blacklists</p>
148 <ul>
149 {
150 websiteInfo.domain_blacklist.engines
151 .sort((a, b) => Number(b.detected) - Number(a.detected))
152 .map((engine) => (
153 engine.detected ? (
154 <li class="blacklist-check blacklisted">
155 <FontAwesome iconName="blacklistFound" />
156 {engine.name}
157 </li>
158 ) : (
159 <li class="blacklist-check not-blacklisted">
160 <FontAwesome iconName="blacklistNotFound" />
161 {engine.name}
162 </li>
163 )
164 ))}
165 </ul>
166 <h4>Website Preview</h4>
167 <img class="preview-shot" src={screenshotUrl} width="300" height="50" />
168 <div class="link-to-web-check">
169 <Button url={`https://web-check.xyz/results/${url}`}>
170 <span>View full report at</span><br /><b class="web-check-title">web-check.xyz</b>
171 </Button>
172 </div>
173
174 </div>
175</div>
176
177
178<style lang="scss">
179.website-info-wrapper {
180 display: flex;
181 flex-wrap: wrap;
182 justify-content: space-between;
183 gap: 1rem;
184 .left, .right {
185 width: calc(50% - 1rem);
186 @media screen and (max-width: 768px){
187 width: 100%;
188 }
189 }
190}
191
192h4 {
193 margin: 1rem 0 0 0;
194 font-size: 1.2rem;
195 }
196 p {
197 margin: 0;
198 display: flex;
199 align-items: center;
200 gap: 0.25rem;
201 :global(svg) {
202 width: 1rem;
203 }
204 img {
205 border-radius: var(--curve-sm);
206 }
207 &.all-good {
208 :global(svg) {
209 color: #35b969;
210 }
211 }
212 &.all-bad {
213 :global(svg) {
214 color: #e3154f;
215 }
216 }
217 }
218 li {
219 :global(svg) {
220 width: 1rem;
221 }
222
223 &.not-blacklisted :global(svg) { color: #35b969; }
224 &.blacklisted :global(svg), &.all-bad :global(svg) { color: #e3154f; }
225
226 }
227 ul {
228 padding-left: 0;
229 list-style: none;
230 max-height: 300px;
231 overflow-y: auto;
232 overflow-x: hidden;
233 img {
234 border-radius: var(--curve-sm);
235 }
236 .list-item {
237 display: flex;
238 flex-direction: column;
239 margin-bottom: 0.5rem;
240 .date-block {
241
242 font-size: 0.8rem;
243 opacity: 0.7;
244 }
245 }
246 &.list-table {
247 font-size: 0.9rem;
248 padding-left: 0;
249 li {
250 display: flex;
251 justify-content: space-between;
252 padding: 0.1rem 0;
253 .lbl {
254 font-weight: 500;
255 }
256 &:not(:last-child) {
257 border-bottom: 1px solid #5f53f440;
258 }
259 }
260 }
261 }
262
263 .website-title, .website-description {
264 font-size: 0.9rem;
265 opacity: 0.8;
266 display: -webkit-box;
267 -webkit-line-clamp: 1;
268 -webkit-box-orient: vertical;
269 overflow: hidden;
270 border-left: 2px solid var(--accent-3);
271 padding-left: 0.5rem;
272 }
273 .website-title {
274 font-weight: 500;
275 }
276 .website-description {
277 font-style: italic;
278 -webkit-line-clamp: 3;
279 }
280 .explainer {
281 font-size: 0.8rem;
282 opacity: 0.8;
283 font-style: italic;
284 }
285
286 .risk {
287 font-size: 2rem;
288 width: fit-content;
289 padding: 0.5rem 0.5rem;
290 border-radius: var(--curve-lg);
291 border: 4px solid;
292 margin: 0.5rem 0;
293 font-weight: bold;
294
295 &.risk-unknown { --rating-color: grey; }
296 &.risk-safe { --rating-color: #35b969; }
297 &.risk-moderately-safe { --rating-color: #c7cc22; }
298 &.risk-risky { --rating-color: #df8b1e; }
299 &.risk-dangerous { --rating-color: #df541e; }
300 &.risk-very-dangerous { --rating-color: #df1e1e; }
301 color: var(--rating-color);
302 border-color: var(--rating-color);
303 }
304
305 .preview-shot {
306 width: 95%;
307 height: auto;
308 border-radius: var(--curve-sm);
309 border: 2px solid var(--accent-3);
310 margin: 0.5rem auto;
311 display: flex;
312 }
313
314 .link-to-web-check {
315 width: 180px;
316 float: right;
317 font-size: 1rem;
318 :global(.button) {
319 background: var(--accent-3);
320 }
321 span {
322 font-size: 0.8rem;
323 }
324 .web-check-title {
325 font-size: 1.4rem;
326 }
327 }
328
329</style>