fix: hwid ignore for browsers
This commit is contained in:
+58
-19
@@ -4932,30 +4932,26 @@ DNS-over-HTTPS with IP:
|
||||
return true;
|
||||
}
|
||||
|
||||
$devices = $this->getHwidDevicesByUser($client['id']);
|
||||
$hwid = trim($_SERVER['HTTP_X_HWID'] ?? '');
|
||||
$over = false;
|
||||
$devices = $this->getHwidDevicesByUser($client['id']);
|
||||
$hwid = trim($_SERVER['HTTP_X_HWID'] ?? '');
|
||||
$isBrowser = $this->isBrowserRequest();
|
||||
|
||||
if ($hwid === '') {
|
||||
if (count($devices) >= $limit) {
|
||||
$over = true;
|
||||
}
|
||||
} else {
|
||||
$isNew = !isset($devices[$hwid]);
|
||||
if ($isNew && count($devices) >= $limit) {
|
||||
$over = true;
|
||||
} else {
|
||||
$this->setHwidDevice($client['id'], $hwid, [
|
||||
'time' => time(),
|
||||
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
|
||||
'device_os' => $_SERVER['HTTP_X_DEVICE_OS'] ?? '',
|
||||
'os_version' => $_SERVER['HTTP_X_VER_OS'] ?? '',
|
||||
'device_model' => $_SERVER['HTTP_X_DEVICE_MODEL'] ?? '',
|
||||
]);
|
||||
if ($isBrowser) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$message = 'HWID device limit exceeded';
|
||||
header('announce: base64:' . base64_encode($message));
|
||||
header('X-HWID-Status: ' . $message);
|
||||
header('HTTP/1.1 429 Too Many Requests', true, 429);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($over) {
|
||||
$isNew = !isset($devices[$hwid]);
|
||||
|
||||
if ($isNew && count($devices) >= $limit) {
|
||||
$message = 'HWID device limit exceeded';
|
||||
header('announce: base64:' . base64_encode($message));
|
||||
header('X-HWID-Status: ' . $message);
|
||||
@@ -4963,9 +4959,52 @@ DNS-over-HTTPS with IP:
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->setHwidDevice($client['id'], $hwid, [
|
||||
'time' => time(),
|
||||
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
|
||||
'device_os' => $_SERVER['HTTP_X_DEVICE_OS'] ?? '',
|
||||
'os_version' => $_SERVER['HTTP_X_VER_OS'] ?? '',
|
||||
'device_model' => $_SERVER['HTTP_X_DEVICE_MODEL'] ?? '',
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function isBrowserRequest()
|
||||
{
|
||||
$userAgent = $_SERVER['HTTP_USER_AGENT'] ?? '';
|
||||
$accept = $_SERVER['HTTP_ACCEPT'] ?? '';
|
||||
|
||||
if ($userAgent === '' && $accept === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
$browserPatterns = [
|
||||
'Mozilla/',
|
||||
'Chrome/',
|
||||
'Safari/',
|
||||
'Firefox/',
|
||||
'Edge/',
|
||||
'Edg/',
|
||||
'MSIE ',
|
||||
'Trident/',
|
||||
'Opera/',
|
||||
'OPR/',
|
||||
];
|
||||
|
||||
foreach ($browserPatterns as $pattern) {
|
||||
if (stripos($userAgent, $pattern) !== false) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (stripos($accept, 'text/html') !== false) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public function switchSilence()
|
||||
{
|
||||
$c = $this->getPacConf();
|
||||
|
||||
Reference in New Issue
Block a user