Skip to content

Commit 5a92a31

Browse files
tbradshamatticbot
authored andcommitted
Status: Remove host guess based on DNS (#44325)
* Remove DNS host guess * Add changelog Committed via a GitHub action: https://github.com/Automattic/jetpack/actions/runs/16321771182 Upstream-Ref: Automattic/jetpack@87ca9eb
1 parent b71a030 commit 5a92a31

File tree

4 files changed

+93
-209
lines changed

4 files changed

+93
-209
lines changed

jetpack_vendor/automattic/jetpack-status/src/class-host.php

Lines changed: 2 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -135,123 +135,15 @@ public function get_source_query() {
135135
return '';
136136
}
137137

138-
/**
139-
* Returns an array of nameservers for the current site.
140-
*
141-
* @param string $domain The domain of the site to check.
142-
* @return array
143-
*/
144-
public function get_nameserver_dns_records( $domain ) {
145-
if ( ! function_exists( 'dns_get_record' ) ) {
146-
return array();
147-
}
148-
149-
$dns_records = dns_get_record( $domain, DNS_NS ); // Fetches the DNS records of type NS (Name Server)
150-
if ( false === $dns_records ) {
151-
return array();
152-
}
153-
154-
$nameservers = array();
155-
foreach ( $dns_records as $record ) {
156-
if ( isset( $record['target'] ) ) {
157-
$nameservers[] = $record['target']; // Adds the nameserver to the array
158-
}
159-
}
160-
161-
return $nameservers; // Returns an array of nameserver names
162-
}
163-
164-
/**
165-
* Given a DNS entry, will return a hosting provider if one can be determined. Otherwise, will return 'unknown'.
166-
* Sourced from: fbhepr%2Skers%2Sjcpbz%2Sjc%2Qpbagrag%2Syvo%2Subfgvat%2Qcebivqre%2Sanzrfreiref.cuc-og
167-
*
168-
* @param string $domain The domain of the site to check.
169-
* @return string The hosting provider of 'unknown'.
170-
*/
171-
public function get_hosting_provider_by_nameserver( $domain ) {
172-
$known_nameservers = array(
173-
'bluehost' => array(
174-
'.bluehost.com',
175-
),
176-
'dreamhost' => array(
177-
'.dreamhost.com',
178-
),
179-
'mediatemple' => array(
180-
'.mediatemple.net',
181-
),
182-
'xserver' => array(
183-
'.xserver.jp',
184-
),
185-
'namecheap' => array(
186-
'.namecheaphosting.com',
187-
),
188-
'hostmonster' => array(
189-
'.hostmonster.com',
190-
),
191-
'justhost' => array(
192-
'.justhost.com',
193-
),
194-
'digitalocean' => array(
195-
'.digitalocean.com',
196-
),
197-
'one' => array(
198-
'.one.com',
199-
),
200-
'hostpapa' => array(
201-
'.hostpapa.com',
202-
),
203-
'siteground' => array(
204-
'.sgcloud.net',
205-
'.sgedu.site',
206-
'.sgsrv1.com',
207-
'.sgvps.net',
208-
'.siteground.biz',
209-
'.siteground.net',
210-
'.siteground.eu',
211-
),
212-
'inmotion' => array(
213-
'.inmotionhosting.com',
214-
),
215-
'ionos' => array(
216-
'.ui-dns.org',
217-
'.ui-dns.de',
218-
'.ui-dns.biz',
219-
'.ui-dns.com',
220-
),
221-
);
222-
223-
$dns_records = $this->get_nameserver_dns_records( $domain );
224-
$dns_records = array_map( 'strtolower', $dns_records );
225-
226-
foreach ( $known_nameservers as $host => $ns_patterns ) {
227-
foreach ( $ns_patterns as $ns_pattern ) {
228-
foreach ( $dns_records as $record ) {
229-
if ( false !== strpos( $record, $ns_pattern ) ) {
230-
return $host;
231-
}
232-
}
233-
}
234-
}
235-
236-
return 'unknown';
237-
}
238-
239138
/**
240139
* Returns a guess of the hosting provider for the current site based on various checks.
241140
*
242141
* @since 5.0.4 Added $guess parameter.
243-
*
244-
* @param bool $guess Whether to guess the hosting provider.
142+
* @since 5.4.1-alpha Removed $guess parameter.
245143
*
246144
* @return string
247145
*/
248-
public function get_known_host_guess( $guess = true ) {
249-
$host = Cache::get( 'host_guess' );
250-
251-
if ( null !== $host ) {
252-
return $host;
253-
}
254-
146+
public function get_known_host_guess() {
255147
// First, let's check if we can recognize provider manually:
256148
switch ( true ) {
257149
case $this->is_woa_site():
@@ -275,14 +167,6 @@ public function get_known_host_guess( $guess = true ) {
275167
break;
276168
}
277169

278-
// Second, let's check if we can recognize provider by nameservers.
279-
// Only do this if we're asked to guess.
280-
$domain = isset( $_SERVER['SERVER_NAME'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_NAME'] ) ) : '';
281-
if ( $provider === 'unknown' && ! empty( $domain ) && $guess ) {
282-
$provider = $this->get_hosting_provider_by_nameserver( $domain );
283-
}
284-
285-
Cache::set( 'host_guess', $provider );
286170
return $provider;
287171
}
288172

0 commit comments

Comments
 (0)