Add new purge contacts option to admin server blocklist
- Move adding a server domain pattern to the blocklist in a separate module to allow reviewing the list of known servers that would be affected
This commit is contained in:
@@ -117,6 +117,33 @@ class GServer
|
||||
return self::getID($url, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves all the servers which base domain are matching the provided domain pattern
|
||||
*
|
||||
* The pattern is a simple fnmatch() pattern with ? for single wildcard and * for multiple wildcard
|
||||
*
|
||||
* @param string $pattern
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function listByDomainPattern(string $pattern): array
|
||||
{
|
||||
$likePattern = 'http://' . strtr($pattern, ['_' => '\_', '%' => '\%', '?' => '_', '*' => '%']);
|
||||
|
||||
// The SUBSTRING_INDEX returns everything before the eventual third /, which effectively trims an
|
||||
// eventual server path and keep only the server domain which we're matching against the pattern.
|
||||
$sql = "SELECT `gserver`.*, COUNT(*) AS `contacts`
|
||||
FROM `gserver`
|
||||
LEFT JOIN `contact` ON `gserver`.`id` = `contact`.`gsid`
|
||||
WHERE SUBSTRING_INDEX(`gserver`.`nurl`, '/', 3) LIKE ?
|
||||
AND NOT `gserver`.`failed`
|
||||
GROUP BY `gserver`.`id`";
|
||||
|
||||
$stmt = DI::dba()->p($sql, $likePattern);
|
||||
|
||||
return DI::dba()->toArray($stmt);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given server is reachable
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user