diff --git a/public/auth/login.php b/public/auth/login.php index a30ca70..0b02893 100644 --- a/public/auth/login.php +++ b/public/auth/login.php @@ -3,7 +3,6 @@ namespace Misuzu; use Misuzu\AuthToken; use Misuzu\Config\CfgType; -use Misuzu\Net\IPAddress; use Misuzu\Users\User; use Misuzu\Users\UserNotFoundException; use Misuzu\Users\UserAuthSession; diff --git a/public/auth/twofactor.php b/public/auth/twofactor.php index af31b16..cee8a1e 100644 --- a/public/auth/twofactor.php +++ b/public/auth/twofactor.php @@ -1,7 +1,6 @@ 4, - self::VERSION_6 => 16, - ]; - - public const DEFAULT_V4 = '127.1'; - public const DEFAULT_V6 = '::1'; - - public static function remote(string $fallback = self::DEFAULT_V6): string { + public static function remote(string $fallback = '::1'): string { return $_SERVER['REMOTE_ADDR'] ?? $fallback; } @@ -32,81 +18,4 @@ final class IPAddress { return $fallback; } } - - public static function rawWidth(int $version): int { - return isset(self::SIZES[$version]) ? self::SIZES[$version] : 0; - } - - public static function detectStringVersion(string $address): int { - if(filter_var($address, FILTER_VALIDATE_IP) !== false) { - if(filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) !== false) - return self::VERSION_6; - - if(filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4) !== false) - return self::VERSION_4; - } - - return self::VERSION_UNKNOWN; - } - - public static function detectRawVersion(string $address): int { - $addressLength = strlen($address); - - foreach(self::SIZES as $version => $length) { - if($length === $addressLength) - return $version; - } - - return self::VERSION_UNKNOWN; - } - - public static function cidrToRaw(string $cidr): ?array { - if(strpos($cidr, '/') !== false) { - [$subnet, $mask] = explode('/', $cidr, 2); - } else { - $subnet = $cidr; - } - - try { - $subnet = inet_pton($subnet); - } catch(Exception $ex) { - return null; - } - - $mask = empty($mask) ? null : (int)$mask; - - return compact('subnet', 'mask'); - } - - public static function matchCidr(string $address, string $cidr): bool { - $address = inet_pton($address); - $cidr = self::cidrToRaw($cidr); - return self::matchCidrRaw($address, $cidr['subnet'], $cidr['mask']); - } - - public static function matchCidrRaw(string $address, string $subnet, ?int $mask = null): bool { - $version = self::detectRawVersion($subnet); - - if($version === self::VERSION_UNKNOWN) - return false; - - $bits = self::SIZES[$version] * 8; - - if(empty($mask)) - $mask = $bits; - - if($mask < 1 || $mask > $bits || $version !== self::detectRawVersion($subnet)) - return false; - - for($i = 0; $i < ceil($mask / 8); $i++) { - $byteMask = (0xFF00 >> max(0, min(8, $mask - ($i * 8)))) & 0xFF; - $addressByte = ord($address[$i]) & $byteMask; - $subnetByte = ord($subnet[$i]) & $byteMask; - - if($addressByte !== $subnetByte) - return false; - } - - return true; - } } diff --git a/src/Net/socket.php b/src/Net/socket.php deleted file mode 100644 index ac4a467..0000000 --- a/src/Net/socket.php +++ /dev/null @@ -1,2 +0,0 @@ -