web/src/utils/fetch-website-info.ts
146 lines · 2863 bytes
1
2export const fetchWebsiteInfo = async (url: string): Promise<WebsiteData | null> => {
3 const endpoint = `https://site-info-fetch.as93.workers.dev/?url=${url}`;
4 try {
5 return await fetch(endpoint).then((res) => res.json());
6 } catch (error) {
7 console.error('Error fetching website info:', error);
8 return null;
9 }
10};
11
12interface DNSRecord {
13 target: string;
14 ip: string;
15 country_code: string;
16 country_name: string;
17 isp: string;
18}
19
20interface DNSRecords {
21 ns: {
22 records: DNSRecord[];
23 };
24 mx: {
25 records: DNSRecord[];
26 };
27}
28
29interface Engine {
30 name: string;
31 reference: string;
32 detected: boolean;
33}
34
35interface DomainBlacklist {
36 engines: Engine[];
37 detections: number;
38}
39
40interface FileType {
41 signature: string;
42 extension: string;
43 headers: string;
44}
45
46interface GeoLocation {
47 countries: string[];
48}
49
50interface HtmlForms {
51 number_of_total_forms: number;
52 number_of_total_input_fields: number;
53 two_text_inputs_in_a_form: boolean;
54 credit_card_field_present: boolean;
55 password_field_present: boolean;
56 email_field_present: boolean;
57}
58
59interface Redirection {
60 found: boolean;
61 external: boolean;
62 url: string;
63 redirects: any[];
64}
65
66interface ResponseHeaders {
67 code: number;
68 status: string;
69 date: string;
70 last_modified: string;
71 etag: string;
72 accept_ranges: string;
73 vary: string;
74 content_encoding: string;
75 cache_control: string;
76 content_length: string;
77 content_type: string;
78 age: string;
79 content_security_policy_report_only: string;
80 strict_transport_security: string;
81 public_key_pins_report_only: string;
82 x_frame_options: string;
83 x_content_type_options: string;
84 x_xss_protection: string;
85 referrer_policy: string;
86 x_permitted_cross_domain_policies: string;
87 onion_location: string;
88}
89
90interface RiskScore {
91 result: number;
92}
93
94interface SecurityChecks {
95 [key: string]: boolean | string;
96}
97
98interface ServerDetails {
99 ip: string;
100 hostname: string;
101 continent_code: string;
102 continent_name: string;
103 country_code: string;
104 country_name: string;
105 region_name: string;
106 city_name: string;
107 latitude: number;
108 longitude: number;
109 isp: string;
110 asn: string;
111}
112
113interface SiteCategory {
114 [key: string]: boolean;
115}
116
117interface UrlParts {
118 scheme: string;
119 host: string;
120 host_nowww: string;
121 port: null | number;
122 path: null | string;
123 query: null | string;
124}
125
126interface WebPage {
127 title: string;
128 description: string;
129 keywords: string;
130}
131
132export interface WebsiteData {
133 dns_records: DNSRecords;
134 domain_blacklist: DomainBlacklist;
135 file_type: FileType;
136 geo_location: GeoLocation;
137 html_forms: HtmlForms;
138 redirection: Redirection;
139 response_headers: ResponseHeaders;
140 risk_score: RiskScore;
141 security_checks: SecurityChecks;
142 server_details: ServerDetails;
143 site_category: SiteCategory;
144 url_parts: UrlParts;
145 web_page: WebPage;
146}